Created
February 23, 2018 09:37
-
-
Save vakrilov/7e5d24ec8873b1df710012e6a9b3294b to your computer and use it in GitHub Desktop.
Notify Layout Event Implementation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
if (isAndroid) { | |
const owner = this; | |
this.listener = new android.view.View.OnLayoutChangeListener({ | |
onLayoutChange( | |
v: android.view.View, | |
left: number, top: number, right: number, bottom: number, | |
oldLeft: number, oldTop: number, oldRight: number, oldBottom: number): void { | |
owner.notifyLayoutChanged(); | |
} | |
}); | |
(<android.view.View>nativeView).addOnLayoutChangeListener(this.listener); | |
} | |
return nativeView; | |
} | |
onLayout(left: number, top: number, right: number, bottom: number): void { | |
super.onLayout(left, top, right, bottom); | |
if (isIOS) { | |
this.notifyLayoutChanged(); | |
} | |
} | |
notifyLayoutChanged() { | |
this.notify({ object: this, eventName: "layout" }); | |
} | |
} | |
// Register tag in the ns-angular renderer | |
registerElement("notify-layout-view", () => NotifyLayoutView); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment