mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Performance improvements after profiling the android flexbox example
This commit is contained in:
@@ -12,11 +12,14 @@ import {
|
||||
|
||||
export * from "./flexbox-layout-common";
|
||||
|
||||
let widgetFlexboxLayout: typeof org.nativescript.widgets.FlexboxLayout;
|
||||
let widgetLayoutParams: typeof org.nativescript.widgets.FlexboxLayout.LayoutParams;
|
||||
|
||||
function makeNativeSetter<T>(setter: (lp: org.nativescript.widgets.FlexboxLayout.LayoutParams, value: T) => void) {
|
||||
return function(this: View, value: T) {
|
||||
const nativeView: android.view.View = this.nativeView;
|
||||
const lp = nativeView.getLayoutParams() || new org.nativescript.widgets.FlexboxLayout.LayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.FlexboxLayout.LayoutParams) {
|
||||
const lp = nativeView.getLayoutParams() || new widgetLayoutParams();
|
||||
if (lp instanceof widgetLayoutParams) {
|
||||
setter(lp, value);
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
@@ -80,7 +83,11 @@ export class FlexboxLayout extends FlexboxLayoutBase {
|
||||
nativeView: org.nativescript.widgets.FlexboxLayout;
|
||||
|
||||
public createNativeView() {
|
||||
return new org.nativescript.widgets.FlexboxLayout(this._context);
|
||||
if (!widgetFlexboxLayout) {
|
||||
widgetFlexboxLayout = org.nativescript.widgets.FlexboxLayout;
|
||||
widgetLayoutParams = widgetFlexboxLayout.LayoutParams;
|
||||
}
|
||||
return new widgetFlexboxLayout(this._context);
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
@@ -127,29 +134,32 @@ export class FlexboxLayout extends FlexboxLayoutBase {
|
||||
super._updateNativeLayoutParams(child);
|
||||
|
||||
const lp = <org.nativescript.widgets.FlexboxLayout.LayoutParams>child.nativeView.getLayoutParams();
|
||||
lp.order = child.order;
|
||||
lp.flexGrow = child.flexGrow;
|
||||
lp.flexShrink = child.flexShrink;
|
||||
lp.wrapBefore = child.flexWrapBefore;
|
||||
lp.alignSelf = alignSelfMap[child.alignSelf];
|
||||
const style = child.style;
|
||||
lp.order = style.order;
|
||||
lp.flexGrow = style.flexGrow;
|
||||
lp.flexShrink = style.flexShrink;
|
||||
lp.wrapBefore = style.flexWrapBefore;
|
||||
lp.alignSelf = alignSelfMap[style.alignSelf];
|
||||
child.nativeView.setLayoutParams(lp);
|
||||
}
|
||||
|
||||
public _setChildMinWidthNative(child: View): void {
|
||||
child._setMinWidthNative(0);
|
||||
const lp = child.nativeView.getLayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.FlexboxLayout.LayoutParams) {
|
||||
lp.minWidth = Length.toDevicePixels(child.minWidth, 0);
|
||||
child.nativeView.setLayoutParams(lp);
|
||||
const nativeView = child.nativeView;
|
||||
const lp = nativeView.getLayoutParams();
|
||||
if (lp instanceof widgetLayoutParams) {
|
||||
lp.minWidth = Length.toDevicePixels(child.style.minWidth, 0);
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
public _setChildMinHeightNative(child: View): void {
|
||||
child._setMinHeightNative(0);
|
||||
const lp = child.nativeView.getLayoutParams();
|
||||
if (lp instanceof org.nativescript.widgets.FlexboxLayout.LayoutParams) {
|
||||
lp.minHeight = Length.toDevicePixels(child.minHeight, 0);
|
||||
child.nativeView.setLayoutParams(lp);
|
||||
const nativeView = child.nativeView;
|
||||
const lp = nativeView.getLayoutParams();
|
||||
if (lp instanceof widgetLayoutParams) {
|
||||
lp.minHeight = Length.toDevicePixels(child.style.minHeight, 0);
|
||||
nativeView.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user