Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: requestlayout improvements #9122

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/ui/src/issues/issue-7469-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ let loaded = false;
let isIn1 = false;

function updateVcToggleText() {
vcToggle.text = `Container is${reusableItem.reusable ? ' ' : ' NOT '}Reusable`
vcToggle.text = `Container is${reusableItem.reusable ? ' ' : ' NOT '}Reusable`;
}

export function pageLoaded(args) {
Expand Down Expand Up @@ -82,7 +82,7 @@ export function makeReusable(args: EventData) {
}
(args.object as any).___reusableRan = true;
(args.object as any).reusable = true;
if(args.object === reusableItem) {
if (args.object === reusableItem) {
updateVcToggleText();
}
}
Expand Down
10 changes: 10 additions & 0 deletions packages/core/ui/core/properties/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1363,13 +1363,23 @@ function inheritableCssPropertyValuesOn(style: Style): Array<{ property: Inherit
type PropertyInterface = Property<ViewBase, any> | CssProperty<Style, any> | CssAnimationProperty<Style, any>;

export const initNativeView = profile('"properties".initNativeView', function initNativeView(view: ViewBase): void {
const wasSuspended = view.suspendRequestLayout;
view.suspendRequestLayout = true;
if (view._suspendedUpdates) {
applyPendingNativeSetters(view);
} else {
applyAllNativeSetters(view);
}
// Would it be faster to delete all members of the old object?
view._suspendedUpdates = {};

// if the view requestLayout was not suspended before
// it means we can request a layout if needed.
// will be done after otherwise
view.suspendRequestLayout = wasSuspended;
if (!wasSuspended && view.isLayoutRequestNeeded) {
view.requestLayout();
}
});

export function applyPendingNativeSetters(view: ViewBase): void {
Expand Down
20 changes: 19 additions & 1 deletion packages/core/ui/core/view-base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,10 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
if (this._isLoaded) {
return;
}

// the view is going to be layed out after
// no need for requestLayout which can be pretty slow because
// called a lot and going all up the chain to the page
this.suspendRequestLayout = true;
this._isLoaded = true;
this._cssState.onLoaded();
this._resumeNativeUpdates(SuspendType.Loaded);
Expand All @@ -442,6 +445,7 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
return true;
});

this.suspendRequestLayout = false;
this._emit('loaded');
}

Expand Down Expand Up @@ -658,6 +662,20 @@ export abstract class ViewBase extends Observable implements ViewBaseDefinition
}
}

_requestLayoutNeeded = false;

get isLayoutRequestNeeded() {
return this._requestLayoutNeeded;
}

_suspendRequestLayout = false;
set suspendRequestLayout(value: boolean) {
this._suspendRequestLayout = value;
}
get suspendRequestLayout() {
return this._suspendRequestLayout;
}

@profile
public requestLayout(): void {
// Default implementation for non View instances (like TabViewItem).
Expand Down
5 changes: 5 additions & 0 deletions packages/core/ui/core/view/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,11 @@ export class View extends ViewCommon {

@profile
public requestLayout(): void {
if (this._suspendRequestLayout) {
this._requestLayoutNeeded = true;
return;
}
this._requestLayoutNeeded = false;
super.requestLayout();
if (this.nativeViewProtected) {
this.nativeViewProtected.requestLayout();
Expand Down
14 changes: 13 additions & 1 deletion packages/core/ui/core/view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,21 @@ export class View extends ViewCommon implements ViewDefinition {
this.once(View.loadedEvent, () => setupAccessibleView(this));
}

requestLayoutIfNeeded() {
if (this.isLayoutRequired) {
this._requestLayoutNeeded = false;
this.requestLayout();
}
}

public requestLayout(): void {
super.requestLayout();
if (this._suspendRequestLayout) {
this._requestLayoutNeeded = true;
return;
}
this._requestLayoutNeeded = false;
this._privateFlags |= PFLAG_FORCE_LAYOUT;
super.requestLayout();

const nativeView = this.nativeViewProtected;
if (nativeView && nativeView.setNeedsLayout) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/ui/text-base/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export class TextBase extends TextBaseCommon {
[paddingLeftProperty.setNative](value: CoreTypes.LengthType) {
org.nativescript.widgets.ViewHelper.setPaddingLeft(this.nativeTextViewProtected, Length.toDevicePixels(value, 0) + Length.toDevicePixels(this.style.borderLeftWidth, 0));
}

[accessibilityIdentifierProperty.setNative](value: string): void {
// we override the default setter to apply it on nativeTextViewProtected
const id = Utils.ad.resources.getId(':id/nativescript_accessibility_id');
Expand Down