Skip to content

Instantly share code, notes, and snippets.

View EddyVerbruggen's full-sized avatar
🔌
plugged in

Eddy Verbruggen EddyVerbruggen

🔌
plugged in
View GitHub Profile
@EddyVerbruggen
EddyVerbruggen / label-max-lines.directive.ts
Last active November 22, 2023 06:13 — forked from m-abs/label-max-lines.directive.ts
Directive for NativeScript-angular, adding the property maxLines to Label
// Usage: <Label maxLines="3" .. />
import { Directive, ElementRef, Input, OnInit, OnChanges } from '@angular/core';
import { Label } from 'tns-core-modules/ui/label';
declare const android, NSLineBreakMode: any;
@Directive({
selector: 'Label[maxLines]',
})
@EddyVerbruggen
EddyVerbruggen / AndroidManifest.xml
Last active January 19, 2022 02:55
App links on iOS and Android with NativeScript
/*
Add this to your <activity>, so any link (clicked in fi. an e-mail)
will open your app instead of the website, but only if it matches these whitelisted path patterns
*/
<activity android:launchMode="singleInstance"><!-- set the launchMode property to this value! -->
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.BROWSABLE"/>
@EddyVerbruggen
EddyVerbruggen / base64.ts
Created January 18, 2018 15:51
base64 encoder (btoa) / decoder (aotb) shim for NativeScript
// base64 encoder (btoa) / decoder (atob) which you can use in your NativeScript app.
//
// Usage (assuming you're in some component and this file is in the same folder:
//
// require('./base64');
//
// const username = "My Usernamé";
// usernameBase64Encoded = btoa(username);
// In case you embed a webview in a native app and the native app has a navigation bar you may find
// swiping up from the webview to the header (and releasing your finger on the header) will not fire
// a 'touchend' event on the webview.
//
// This code fixes it in a way where we listen for 'touchmove' events and fire a 'touchend' event
// programmatically in case the user leaves the webview at the top (negative Y coordinate):
document.addEventListener("touchmove", function(e) {
if (e.changedTouches[0].pageY < 0) {
e.preventDefault();
@EddyVerbruggen
EddyVerbruggen / nativescript-ios-caret-color.ts
Last active March 17, 2020 13:09
Changing the caret (cursor) color in NativeScript iOS
export class MyComponent implements AfterViewInit {
// assuming your view has this: <TextField #myTextField text="I have a red caret"></TextField>
@ViewChild("myTextField") myTextField: ElementRef;
ngAfterViewInit(): void {
// note that if you don't have iOS typings you can change 'UITextField' to 'any'
let textField: UITextField = (<TextField>this.myTextField.nativeElement).ios;
textField.tintColor = new Color("red").ios;
}
}
@EddyVerbruggen
EddyVerbruggen / grafana-corona-widget.html
Last active March 16, 2020 16:52
Grafana Corona widget
<!--
- Add a 'Text' widget with the content below (set 'mode' to 'html').
- Make sure to enable JS parsing for this widget by setting the 'disable_sanitize_html' property to 'true' in your grafana.ini.
- For more detailed info, check out fi. https://www.worldometers.info/coronavirus/
- STAY SAFE FOLKS!
-->
<center>
<div style="font-size: 20px">🦠<span id="confirmed"/></div>
<div style="font-size: 16px">💀<span id="deaths" /><span id="deathrate" style="color: #555; padding-left: 8px"/></div>
@EddyVerbruggen
EddyVerbruggen / nativescript-global-tablet-specific-styles.ts
Created June 14, 2017 09:07
Global tablet CSS for NativeScript apps
import { NgModule } from "@angular/core";
import { DeviceType } from "ui/enums";
import { device } from "platform";
import * as application from "application";
const fs = require("file-system");
@NgModule({
// ..
})
@EddyVerbruggen
EddyVerbruggen / toolbar-page.xml
Created December 13, 2018 21:20
nativescript-keyboard-toolbar plugin demo for NativeScript Core
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:kt="nativescript-keyboard-toolbar">
<!-- This GridLayout wrapper is required; it wraps the visible layout and the Toolbar layout(s) -->
<GridLayout>
<StackLayout>
<Label text="Some text"/>
<!-- Add an 'id' property that we can reference below -->
<TextField id="priceTextField" hint="Enter the price" keyboardType="number"/>
</StackLayout>
@EddyVerbruggen
EddyVerbruggen / iOS8 Beta Phonegap fix
Last active December 8, 2018 05:28
iOS8 Beta Phonegap fix: manually set the navigator.userAgent
// temp fix for iOS8 beta 1 (fixed in beta 2), add it after the reference to cordova.js
if (navigator.userAgent === undefined) {
navigator.__defineGetter__('userAgent', function() {
return("Mozilla/5.0 (iPhone; CPU iPhone OS 8_0 like Mac OS X) AppleWebKit");
});
}
@EddyVerbruggen
EddyVerbruggen / nativescript-radlistview-activityindicators-appearance.ts
Last active October 21, 2018 17:04
Change appearance of Activity Indicators in NativeScript RadListView
export class ComponentWithRadListView {
// assuming you have something like this in your view:
// <RadListView (loaded)="onOrderListLoaded($event)">
onOrderListLoaded(args): void {
const listViewElement = <RadListView>args.object;
const tk: any = listViewElement.ios;
if (tk && tk.pullToRefreshView) {
tk.pullToRefreshView.activityIndicator.color = new Color("#4CC55B").ios;