How can I change the iOS status bar color with nativescript, angular2 and typescript? - angularjs

So i've found this npm package:
https://www.npmjs.com/package/nativescript-statusbar
But i'm not able to use a Page element since i'm using angular and typescript.
I already made this:
this.page.backgroundSpanUnderStatusBar= true;
But my Background color is black.
I would need the light status bar from iOS.
Is this possible right now?
Any help much appreciated!

With angular2 in nativescript you can just register and element in your component:
registerElement("StatusBar", () => require("nativescript-statusbar").StatusBar);
And in your view use the tag you created, in that case StatusBar:
<StatusBar ios:barStyle="light" android:barStyle="red"></StatusBar>

You can try the following
import {Component } from "angular2/core";
import frameModule = require("ui/frame");
#Component({
selector: "my-app",
template: `
<StackLayout orientation="vertical">
<Label [text]="message" class="title" (tap)="message = 'OHAI'"></Label>
</StackLayout>
`,
})
export class AppComponent {
ngOnInit() {
var page = frameModule.topmost().currentPage;
page.backgroundSpanUnderStatusBar = true;
if(page.ios){
page.ios.navBarVisibility = "always";
var controller = page.ios.controller;
var navigationBar = controller.navigationBar;
navigationBar.barStyle = 2; // different styles from 0 to 3
}
}
}
More about the possibilities of styling the iOS navigation bar you can find in this tutorial here

Earlier I used 'nativescript-statusbar' package for changing status bar background in my Angular/NativeScript apps. But it leads to problems with the status bar on landscape mode.
So I found a better solution:
import { Page } from "ui/page";
#Component({...})
export class YourAnyComponent {
public constructor(private page: Page) {}
ngOnInit() {
this.page.backgroundColor = '#2c303a';
this.page.backgroundSpanUnderStatusBar = true;
this.page.actionBarHidden = false; // if you want to show only statusbar or - true if you want to show both stutus bar and action bar
}
}

Related

Migrate AngularJS to Angular 8

i need to put this code line (angularJS) in angular 2+ , how can i do this?
I already do some searchs but this line is confusing me.
scope.variable.value = event.color.toHex()
Old Code:
function callColorpicker() {
var colorpicker = $('.colorpicker')
colorpicker.colorpicker().on('changeColor', function(event) {
var scope = angular.element(this).scope()
scope.variable.value = event.color.toHex()
if ($scope.autoapplysass) {
$scope.autoApplySass()
}
})
}
New Code:
callColorpicker() {
var colorpicker = $('.colorpicker')
colorpicker.colorpicker();
var _this = this;
colorpicker.colorpicker().on('changeColor', function(event) {
--> scope.variable.value = event.color.toHex()
if (_this.applySass) {
_this.applySass(false)
}
})
}
In general, if you can avoid jQuery with Angular it's a good thing because Angular handles things completely differently than JQ and in many ways the two step on each other's toes. This can be difficult to troubleshoot and down the line could cause issues that are increasingly harder to diagnose.
In your case, as luck would have it, there is an angular color picker component you could substitute with.
NPMJS page: https://www.npmjs.com/package/ngx-color-picker
Demo: https://zefoy.github.io/ngx-color-picker/
StackBlitz: https://stackblitz.com/github/zefoy/ngx-color-picker/tree/master
install with npm npm install ngx-color-picker --save
Then in app.module.ts
import { ColorPickerModule } from 'ngx-color-picker';
#NgModule({
...
imports: [
...
ColorPickerModule
]
})
In your HTML
<input [(colorPicker)]="color"
[style.background]="color"
(colorPickerChange)="onColorChange($event)" />
and in your component.ts
import { Component, ViewContainerRef } from '#angular/core';
import { ColorPickerService, Cmyk } from 'ngx-color-picker';
constructor(public vcRef: ViewContainerRef, private cpService: ColorPickerService) {}
export class AppComponent {
color: string;
onColorChange(newColor) {
this.color = newColor;
if (_this.applySass) {
_this.applySass(false)
}
}

AngularJS, TypeScript, Component Architecture weird behavior

I've jumped for a while from Angular 6 to Angular JS and I'm trying to code in Component Architecture. The problem is - I'm trying to use ng-show="somevariable" to hide / show a div.
AppRootModule:
export const appRootModule: IModule = module('datawalk', ['asyncFilter'])
.component('appRoot', new AppRootComponent())
.component('postModal', new PostModalComponent())
.service('componentsDataService', ComponentDataService);
PostModalComponent:
export class PostModalComponent {
public template: string;
public controller: Injectable<IControllerConstructor>;
public controllerAs: string;
constructor() {
this.controller = PostModalController;
this.controllerAs = 'postM';
this.template = PostModalTemplateHtml;
}
PostModalController
export class PostModalController implements IController {
public modalVisible: boolean;
/../
constructor(componentsDataService: ComponentDataService) {
/../
this.modalVisible = false;
/../
this.$cds.getModalData().subscribe((data: any) => {
if (data.showMod === true) {
this.modalOpen(data);
}
});
}
public $onInit = async (): Promise<void> => {};
public modalOpen(post: any): void {
console.error(this.modalVisible); // false
this.modalVisible = true;
console.error(this.modalVisible); // true
/../
}
And the template:
<div class="modal" ng-show="modalVisible">
<div class="modal-body">
/../
</div>
</div>
Anyone can tell me what I'm doing wrong?
console logs shows that the variable changes, but nothing happen, modal div is still hidden.
OK. So I've figured it out.
That's not a problem of code, but the problem is inside my IDE.
WebStorm has an issue - it does not recognize a controllerAs property in HTML templates of AngularJS in component architecture.
Also tslint works faulty.
I don't recommend to use that with AngularJS with component architecture.
Vs Code works perfect with that.

Implementing ng2-completer

I am currently using ng2-completer (https://github.com/oferh/ng2-completer) for angular 2 and struggling to add in the suggestions to have the full response instead of just having one value.
Also, when the suggestion is selected, how is the method assigned to handle this?
The code I've got so far is:
import { Component } from '#angular/core';
import { AutoComplete } from './autocomplete';
import { CompleterService, CompleterData, RemoteData } from 'ng2-completer';
import { SearchComponent } from './search.component';
import { QueryService } from './query.service';
#Component({
selector: 'app-home',
template: `<ng2-completer [(ngModel)]="searchStr" [dataService]="dataService" [minSearchLength]="0" [inputClass]="['form-control input-list']" [autofocus]="['true']" [selected]="selected()"></ng2-completer>`,
//directives: [ AutoComplete ]
})
export class HomeComponent {
public searchStr: string;
private dataService: CompleterData;
constructor(private completerService: CompleterService, private queryService: QueryService) {
//this.dataService = completerService.local(this.searchData, 'color', 'color');
this.dataService = completerService.remote('http://localhost:61227/machine/?query=','ComputerHostname, AssetID', 'ComputerHostname').descriptionField('ComputerType');
//this.dataService = this.queryService.search(searchStr).then(items => this.items = items);
}
selected () {
console.log("test");
}
}
However it shows the following error:
Can't bind to 'selected' since it isn't a known property of 'ng2-completer'.
selected is an event and not a property and therefor the syntax for it (as described in Angular template syntax) should be (selected)="selected($event)"
autofocus expects a boolean value (see in ng2-completer doc) not an array so you should use [autofocus]="true"

Add Property to my NPM Module

This might be answered, but damn if I can find it . I am creating a module, and its working, the issue is I want to assign a property to another property on my module.
so in angular 2 (with ng-module) I have created a simple panel
<simple-panel name="MyPanel"></simple-panel>
I have it working great, the issue is I want to assign a property to the name Property now and I have no idea what is the best way to do this.
so I would like to return {{MyPanel.thisProperty}} for use on the page where I am calling the tag.
here is a sample of what I am doing, stripped down for this question
here is my simple-panel.ts
import {Component,NgModule,ModuleWithProviders, Directive, Input} from '#angular/core';
/**
* Content of the edit panel.
*/
#Directive({
selector: 'simple-panel-edit-panel-content'
})
export class SimplePanelEditPanelContent {}
#Component({
selector: 'simple-panel',
templateUrl: 'simple-panel.html',
styleUrls: ['simple-panel.css'],
encapsulation: ViewEncapsulation.None
})
export class SimplePanel{
private _name: string;
private _announceedit: boolean = false;
private _buttonname: string = 'edit';
/** This sets the Name as a variable that can be used. */
#Input()
get name(): string { return this._name; }
set name(value) { this._name = value; }
/**Sets the Edit Announcement */
#Input()
get editannounce(): boolean { return this._announceedit; }
set editannounce(value: boolean) {
if (!value) {
this._announceedit = true;
this._buttonname = 'search';
}else{
this._announceedit = false;
this._buttonname = 'edit';
}
}
}
#NgModule({
exports: [SimplePanel,SimplePanelEditPanelContent],
declarations: [SimplePanel,SimplePanelEditPanelContent],
})
export class SimplePanelComponent {
static forRoot(): ModuleWithProviders {
return {
ngModule: SimplePanelComponent,
providers: []
};
}
}
here is the simple-panel.html
<md-card>
<md-card-title-group>
<button md-raised-button (click)="editannounce=editannounce;"><md-icon>{{ _buttonname }}</md-icon></button>
</md-card-title-group>
<md-card-content>
<ng-content select="simple-panel-edit-panel-content"></ng-content>
</md-card-content>
<md-card-actions>
<button md-raised-button (click)="editannounce = editannounce"><md-icon>save</md-icon> SAVE</button>
</md-card-actions>
</md-card>
when someone uses the module, a panel is created with a button
when someone clicks the button I can access the variable within the template above, but what I want to do is actually access a variable that is used on the page itself where they call the module to use. it would be nice to have it named MyPanel.announceedit or MyPanel.editable as an example, but the main thing is that a variable is created, and watched, when it changes it passes it back up to where the module is bieng used and allows user the ability to access it within the content area, so if they added an input and wanted to see if the button was clicked to set the readOnly attribute they could. Hopefully this makes more sense.
If you write it like
<simple-panel [name]="MyPanel"></simple-panel>
in the component that includes this html, you can access/set MyPanel with a simple this.MyPanel.
And in your SimplePanel component
#Input() name;
...
this.name = "something";
is again all you need to set and get that field.

Ancestry with App.addRegions

If you add a region to a layout view using the regions hash like so:
regions: {
compositeRegion: '#ui.compositeViewDiv',
modalRegion:{
regionClass:modal,
selector:'.modalRegion'
}
}
The views that you show in those regions can call triggerMethod and trigger an event on their parent view.
If instead I build my regions (for instance, in a composite view or even an item view) like so:
App.addRegions({
compositeRegion: '#ui.compositeViewDiv',
modalRegion:{
regionClass:modal,
selector:'.modalRegion'
}
Nothing happens when you call triggerMethod. It does not seem to have the _parent attribute defined on the region.
If I manually set _parent to any view, it will trigger a method on the next highest up layout view.
For example, I have a Layout view "A" with a composite view "B", and that composite view "B" has an item view "C". If I create a region using App.addRegions code above in the item view "C", I can then set the _parent and show a view like so:
App.modalRegion._parent = this;
App.modalRegion.show(new someView());
The Layout view "A" childEvent is triggered, not the item view "C", nor the Composite view "B".
If I manually call
this.triggerMethod('sameeventname');
on the item view "C", it WILL trigger the composite view "B"'s childEvent.
Any ideas? I need to be able to use my modal region (takes any marionette view and turns it into a jQuery-UI modal) from anywhere. It works great when you use it with the layout view region hash. But since there is no region hash in a composite or item view, it works but will not communicate with its parent view.
I would recommend having a look at James Kyle's Marionette Wires, in particular the way services are used to display global components such as modal and flashes in his example.
The basic architecture is an application, with a LayoutView containing a region for each component. This is rendered on initialize and the component is passed the region from the app.
For rendering a view in a modal something like the following should work:
//layout-view.js
import { LayoutView } from 'backbone.marionette';
export const BaseLayout = LayoutView.extend({
regions: {
modal: '.modal',
...
}
});
//app.js
import { Application } from 'backbone.marionette';
import { BaseLayout } from './layout-view';
export const App = Application.extend({
initialize(options = {}) {
this.layout = new Layout({
el: options.el
});
this.layout.render();
}
});
//modal/service.js
import { Service } from 'backbone.service';
const ModalService = Service.extend({
setup(options = {}) {
this.container = options.container;
},
requests: {
show: 'show',
hide: 'hide'
},
show(view) {
this.container.show(view);
},
hide() {
this.container.empty()
}
});
export const modalService = new ModalService();
//main.js
import { App } from './app';
import { modalService } from './modal/service';
const app = new App({
el: '.root-element'
});
modalService.setup({
container: app.layout.modal
});
.... init other components
//someComponent/index.js
import { modalService } from '../modal/service';
...
showView() {
const view = new View();
modalService.request('show', view)
.then(doSomething)
.catch(err => {
console.error(err);
});
},
hideView() {
modalService.request('hide')
.then(doSomething);
}

Resources