Skip to content

Instantly share code, notes, and snippets.

View NathanWalker's full-sized avatar

Nathan Walker NathanWalker

View GitHub Profile
@NathanWalker
NathanWalker / native-class.ios.ts
Last active October 28, 2020 18:30
Example of using a single file containing a single @nativeclass decorated class with NativeScript 7
/**
* {N} 7 uses es2017 targeting
* @NativeClass decorator transforms native class extensions to work with iOS/Android runtimes
* When used in a single file by itself, the transformation modifies the esm export syntax
* Without any other esm exports in the file, you will want to export the symbol at bottom explicitly
* This will ensure a proper esm export of your extended native class symbol will work as expected.
*/
@NativeClass()
class MyNativeClassExt extends NSObject {
@NathanWalker
NathanWalker / usage-intructions.md
Last active June 19, 2021 01:42
@nativescript/schematics with NativeScript 7.x.x and Angular 10.1.x - 11.x.x
  1. Install the latest NativeScript cli (7.x.x)
npm i -g nativescript
  1. Choose A or B depending on your use case:

A) Starting a new Angular web project and adding {N} to it afterwards:

@NathanWalker
NathanWalker / http.interceptor.ts
Last active February 23, 2021 18:43
Simple offline handling with NativeScript using Angular as example
// pseudo code using angular flavor as example
@Injectable({ providedIn: 'root' })
export class SomeHttpInterceptor implements HttpInterceptor {
_mobileOffline = new MobileOffline();
constructor(private mobileStorage: MobileAPIStorageService) {}
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if (!this._mobileOffline.isOnline) {
@NathanWalker
NathanWalker / Shimmer.kt
Last active August 5, 2022 03:10
Shimmer ported to Kotlin
package io.nstudio.ui
import android.animation.ValueAnimator
import android.animation.ValueAnimator.AnimatorUpdateListener
import android.annotation.TargetApi
import android.content.Context
import android.content.res.TypedArray
import android.graphics.Color
import android.graphics.RectF
import android.graphics.Canvas
@NathanWalker
NathanWalker / NativeScript > main.ts
Last active June 30, 2022 04:08
NativeScript for Angular bootstrap
import {
platformNativeScript,
runNativeScriptAngularApp,
} from "@nativescript/angular";
import { AppModule } from "./app/app.module";
// runs the NativeScript application, nothing is bootstrapped yet, as we're only setting up the platform and callbacks
runNativeScriptAngularApp({
// this function will be called when we need to display the application UI
// a major difference from the web is that this module may be destroyed when the user leaves the application and recreated when the user opens it again
@NathanWalker
NathanWalker / Web > main.ts
Created June 30, 2022 04:07
Angular web bootstrap
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic";
import { AppModule } from "./app/app.module";
// locate the app-root and bootstrap the component in it's place
platformBrowserDynamic()
.bootstrapModule(AppModule)
.catch((err) => console.error(err));
@NathanWalker
NathanWalker / NativeScript background service bootstrap
Last active June 30, 2022 04:10
NativeScript for Angular (No UI) module to handle only background services
@NgModule({
imports: [NativeScriptModule],
})
export class BackgroundModule {
ngDoBootstrap() {
// do nothing, this is not an UI module
}
}
const moduleRefPromise = platformNativeScript().bootstrapModule(AppModule);
@NathanWalker
NathanWalker / NativeScript Angular standalone component
Created June 30, 2022 04:11
NativeScript for Angular v14 standalone component
import { Component } from "@angular/core";
import { NativeScriptCommonModule } from "@nativescript/angular";
@Component({
standalone: true,
selector: "hello-standalone",
imports: [NativeScriptCommonModule],
template: `<Label text="Hello, I'm a standalone component"></Label>`,
schemas: [NO_ERRORS_SCHEMA],
})
@NathanWalker
NathanWalker / Angular Directive Sample
Created June 30, 2022 04:11
Angular Directive Sample
import { Directive, ElementRef, inject } from "@angular/core";
@Directive({
selector: "[appHighlight]",
})
export class HighlightDirective {
private el = inject(ElementRef);
constructor() {
this.el.nativeElement.style.backgroundColor = "yellow";
@NathanWalker
NathanWalker / view-directive-usage.component.html
Created June 30, 2022 04:12
NativeScript Angular directive usage sample
<Label appHighlight text="Attribute Directive"></Label>