Skip to content

Instantly share code, notes, and snippets.

View vakrilov's full-sized avatar
💡

Alexander Vakrilov vakrilov

💡
View GitHub Profile
@vakrilov
vakrilov / main.ts
Last active July 25, 2016 10:33
Inject Page
// this import should be first in order to load some required settings (like globals and reflect-metadata)
import {nativeScriptBootstrap} from "nativescript-angular/application";
import {Component} from "@angular/core";
import {RouterConfig} from "@angular/router";
import {NS_ROUTER_DIRECTIVES, nsProvideRouter} from "nativescript-angular/router";
import {Page} from "ui/page";
import {Color} from "color";
@Component({
selector: "my-app",
import {Directive, ViewContainerRef, TemplateRef, Inject} from '@angular/core';
import {Device, platformNames} from "platform";
import {DEVICE} from "nativescript-angular/platform-providers";
@Directive({ selector: "[ifAndroid]" })
export class IfAndroidDirective {
constructor( @Inject(DEVICE) device: Device, container: ViewContainerRef, templateRef: TemplateRef<Object>) {
if (device.os === platformNames.android) {
container.createEmbeddedView(templateRef);
}
@vakrilov
vakrilov / app.component.html
Last active December 9, 2016 12:50
ListView odd/eve template
<StackLayout>
<ListView [items]="listItems" rowHeight="60" [itemTemplateSelector]="templateSelector">
<template nsTemplateKey="odd" let-item="item">
<StackLayout class="odd">
<Image [src]="item.image"></Image>
<Label [text]='item.date' textWrap="true" style="padding-left:10;"></Label>
</StackLayout>
</template>
<template nsTemplateKey="even" let-item="item">
@vakrilov
vakrilov / Plugins3.0.md
Last active June 5, 2017 14:15 — forked from hshristov/Plugins3.0.md
Create UI plugin for NativeScript 3.0

Writing UI plugins for NativeScript

This article will guide you through the process of creating UI plugin and will try to explain new concepts on the way. All the code is in TypeScript and assume you are using NativeScript 3.0 or newer.

In this article you’ll create a simple button plugin to get an idea of how to build your own NativeScript UI plugins.

Before we start we need to create 4 files: my-button.d.ts, my-button-base.ts, my-button.android.ts and my-button.ios.ts.

@vakrilov
vakrilov / component.html
Created September 17, 2017 08:42
Noise detection demo
<StackLayout class="page" rows="auto, auto, *">
<Button text="start" (tap)="start()"></Button>
<Button text="stop" (tap)="stop()"></Button>
<Label text="HEYA" class="h2 text-center" [scaleX]="scale" [scaleY]="scale" margin="100"></Label>
</StackLayout>
@vakrilov
vakrilov / main.js
Created November 1, 2017 14:34
Flashlight
var app = require("tns-core-modules/application");
var plat = require("tns-core-modules/platform");
exports.turnOn = function (args) {
flash(true);
}
exports.turnOff = function (args) {
flash(false);
}
@vakrilov
vakrilov / 1.1 Action-bar
Last active November 13, 2017 16:03
NativeScript 101
<ActionBar title="The Morse Code App" class="action-bar">
</ActionBar>

One of the main goals of [email protected] is to enable more flexible composition of UI. Let's start with some history. Before 4.0 we create Frame control for you (check application.ios.ts and frame.android.ts). Frame control allows you to do navigation forward or backward. While this is convenient it introduce other issues that can't be workaround easliy. For example if you want to have TabView in all pages you have to include it in the xml and set its selectedIndex so that once you navigate to different page a correct TabViewItem is selected. This leads to several problems:

  • parse more xml
  • increase memory usage
  • increase loading time

Same issues apply if you want to have SideDrawer control as a root component.

So in order to resolve these starting with 4.0 applicat

@vakrilov
vakrilov / notify-layout-view.ts
Created February 23, 2018 09:37
Notify Layout Event Implementation
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
import { isAndroid, isIOS } from "tns-core-modules/platform";
import { View } from "tns-core-modules/ui/core/view";
import { registerElement } from "nativescript-angular/element-registry";
export class NotifyLayoutView extends StackLayout {
private listener: android.view.View.OnLayoutChangeListener
public createNativeView() {
const nativeView = super.createNativeView();
@vakrilov
vakrilov / app.component.ts
Last active February 23, 2018 09:38
Notify Layout Event Implementation
import { Component } from "@angular/core";
import { View } from "tns-core-modules/ui/core/view";
@Component({
selector: "ns-app",
template: `
<GridLayout rows="auto * auto">
<Label text="------>>>>>"></Label>
<notify-layout-view row="1" backgroundColor="lightgreen" (layout)="onLayout($event)"></notify-layout-view>
<Label text="------>>>>>" row="2"></Label>