MCPcopy Index your code
hub / github.com/NativeScript/NativeScript / _setupUI

Function _setupUI

packages/core/ui/core/view-base/index.ts:1160–1235  ·  view source on GitHub ↗
(context: any /* android.content.Context */, atIndex?: number, parentIsLoaded?: boolean)

Source from the content-addressed store, hash-verified

1158 */
1159 @profile
1160 public _setupUI(context: any /* android.content.Context */, atIndex?: number, parentIsLoaded?: boolean): void {
1161 if (this._context === context) {
1162 // this check is unnecessary as this function should never be called when this._context === context as it means the view was somehow detached,
1163 // which is only possible by setting reusable = true. Adding it either way for feature flag safety
1164 if (this.reusable) {
1165 if (!this.mIsRootView && this.parent && !this._isAddedToNativeVisualTree) {
1166 const nativeIndex = this.parent._childIndexToNativeChildIndex(atIndex);
1167 this._isAddedToNativeVisualTree = this.parent._addViewToNativeVisualTree(this, nativeIndex);
1168 }
1169 }
1170 return;
1171 } else if (this._context) {
1172 this._tearDownUI(true);
1173 }
1174
1175 this._context = context;
1176
1177 // This will account for nativeView that is created in createNativeView, recycled
1178 // or for backward compatibility - set before _setupUI in iOS constructor.
1179 let nativeView = this.nativeViewProtected;
1180
1181 // if (__ANDROID__) {
1182 // const recycle = this.recycleNativeView;
1183 // if (recycle === "always" || (recycle === "auto" && !this._disableNativeViewRecycling)) {
1184 // nativeView = <android.view.View>getNativeView(context, this.typeName);
1185 // }
1186 // }
1187 if (!nativeView) {
1188 nativeView = this.createNativeView();
1189 }
1190
1191 if (__ANDROID__) {
1192 // this check is also unecessary as this code should never be reached with _androidView != null unless reusable = true
1193 // also adding this check for feature flag safety
1194 if (this._androidView !== nativeView || !this.reusable) {
1195 this._androidView = nativeView;
1196 if (nativeView) {
1197 const className = this.constructor.name;
1198
1199 if (this._isPaddingRelative === undefined) {
1200 this._isPaddingRelative = nativeView.isPaddingRelative();
1201 }
1202
1203 let result: any /* android.graphics.Rect */ = DEFAULT_VIEW_PADDINGS.get(className) || (<any>nativeView).defaultPaddings;
1204 if (result === undefined) {
1205 DEFAULT_VIEW_PADDINGS.set(className, org.nativescript.widgets.ViewHelper.getPadding(nativeView));
1206 (<any>nativeView).defaultPaddings = DEFAULT_VIEW_PADDINGS.get(className);
1207 result = DEFAULT_VIEW_PADDINGS.get(className);
1208 }
1209
1210 if (!nativeView.defaultPaddings) {
1211 nativeView.defaultPaddings = DEFAULT_VIEW_PADDINGS.get(className);
1212 }
1213
1214 this._setDefaultPaddings(result);
1215 }
1216 }
1217 } else {

Callers

nothing calls this directly

Calls 10

_tearDownUIMethod · 0.80
getPaddingMethod · 0.80
_setupUIMethod · 0.80
getMethod · 0.65
createNativeViewMethod · 0.45
setMethod · 0.45
_setDefaultPaddingsMethod · 0.45
eachChildMethod · 0.45

Tested by

no test coverage detected