Skip to content
Open
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
6 changes: 1 addition & 5 deletions packages/core/ui/core/view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1270,11 +1270,7 @@ export class CustomLayoutView extends ContainerView {
const childNativeView: NativeScriptUIView = <NativeScriptUIView>child.nativeViewProtected;

if (parentNativeView && childNativeView) {
if (typeof atIndex !== 'number' || atIndex >= parentNativeView.subviews.count) {
parentNativeView.addSubview(childNativeView);
} else {
parentNativeView.insertSubviewAtIndex(childNativeView, atIndex);
}
IOSHelper.insertSubview(parentNativeView, childNativeView, atIndex);

// Add outer shadow layer manually as it belongs to parent layer tree (this is needed for reusable views)
if (childNativeView.outerShadowContainerLayer && !childNativeView.outerShadowContainerLayer.superlayer) {
Expand Down
5 changes: 5 additions & 0 deletions packages/core/ui/core/view/view-helper/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ export namespace IOSHelper {
export function invalidateStatusBarAppearance(controller?: any /* UIViewController */, reason?: string): void;
export function updateAutoAdjustScrollInsets(controller: any /* UIViewController */, owner: View): void;
export function updateConstraints(controller: any /* UIViewController */, owner: View): void;
/**
* Add `childNativeView` to `parentNativeView` at subview index `atIndex`, or append it when the index is absent or past the end.
* Uses `insertSubview:belowSubview:` — `insertSubview:atIndex:` resolves the index against the layer's sublayers, which also hold non-view layers (gradient backgrounds, shadow layers).
*/
export function insertSubview(parentNativeView: any /* UIView */, childNativeView: any /* UIView */, atIndex?: number): void;
export function layoutView(controller: any /* UIViewController */, owner: View): void;
export function getPositionFromFrame(frame: any /* CGRect */): Position;
export function getFrameFromPosition(position: Position, insets?: Position): any; /* CGRect */
Expand Down
17 changes: 17 additions & 0 deletions packages/core/ui/core/view/view-helper/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,23 @@ export class IOSHelper {
return rootView.safeAreaLayoutGuide;
}

/**
* Add `childNativeView` to `parentNativeView` at subview index `atIndex`, or

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment needs shrinking and correction.

* append it when the index is absent or past the end. Never done with
* `insertSubview:atIndex:`: UIKit resolves that index against the layer's
* sublayers, which also hold the non-view layers core installs (a gradient
* background at sublayer 0, an outer shadow layer per shadowed child), so the
* view lands below the sibling it should precede.
*/
static insertSubview(parentNativeView: UIView, childNativeView: UIView, atIndex?: number): void {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could rename the function to insertNativeSubview to make it distinct for users and plugin maintainers that it doesn't target {N} JS views.

Also, it would be nice to have an android counterpart which could contain the View class implementation by default.

const subviews = parentNativeView.subviews;
if (typeof atIndex !== 'number' || atIndex >= subviews.count) {
parentNativeView.addSubview(childNativeView);
} else {
parentNativeView.insertSubviewBelowSubview(childNativeView, subviews.objectAtIndex(atIndex));
}
}

static layoutView(controller: UIViewController, owner: View): void {
let layoutGuide = controller.view.safeAreaLayoutGuide;
if (!layoutGuide) {
Expand Down
8 changes: 2 additions & 6 deletions packages/core/ui/layouts/liquid-glass-container/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NativeScriptUIView } from '../../utils';
import { supportsGlass } from '../../../utils/constants';
import { GlassEffectType, iosGlassEffectProperty, View } from '../../core/view';
import { GlassEffectType, iosGlassEffectProperty, IOSHelper, View } from '../../core/view';
import { LiquidGlassContainerCommon } from './liquid-glass-container-common';
import { toUIGlassStyle } from '../liquid-glass';

Expand Down Expand Up @@ -39,11 +39,7 @@ export class LiquidGlassContainer extends LiquidGlassContainerCommon {
const childNativeView: NativeScriptUIView = <NativeScriptUIView>child.nativeViewProtected;

if (parentNativeView && childNativeView) {
if (typeof atIndex !== 'number' || atIndex >= parentNativeView.subviews.count) {
parentNativeView.addSubview(childNativeView);
} else {
parentNativeView.insertSubviewAtIndex(childNativeView, atIndex);
}
IOSHelper.insertSubview(parentNativeView, childNativeView, atIndex);

// Add outer shadow layer manually as it belongs to parent layer tree (this is needed for reusable views)
if (childNativeView.outerShadowContainerLayer && !childNativeView.outerShadowContainerLayer.superlayer) {
Expand Down
8 changes: 2 additions & 6 deletions packages/core/ui/layouts/liquid-glass/index.ios.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { NativeScriptUIView } from '../../utils';
import { supportsGlass } from '../../../utils/constants';
import { type GlassEffectType, type GlassEffectVariant, iosGlassEffectProperty, View } from '../../core/view';
import { type GlassEffectType, type GlassEffectVariant, iosGlassEffectProperty, IOSHelper, View } from '../../core/view';
import { LiquidGlassCommon } from './liquid-glass-common';

export class LiquidGlass extends LiquidGlassCommon {
Expand Down Expand Up @@ -35,11 +35,7 @@ export class LiquidGlass extends LiquidGlassCommon {
const childNativeView: NativeScriptUIView = <NativeScriptUIView>child.nativeViewProtected;

if (parentNativeView && childNativeView) {
if (typeof atIndex !== 'number' || atIndex >= parentNativeView.subviews.count) {
parentNativeView.addSubview(childNativeView);
} else {
parentNativeView.insertSubviewAtIndex(childNativeView, atIndex);
}
IOSHelper.insertSubview(parentNativeView, childNativeView, atIndex);

// If the child has an outer shadow layer, ensure it is attached under the child's layer
if (childNativeView.outerShadowContainerLayer && !childNativeView.outerShadowContainerLayer.superlayer) {
Expand Down
6 changes: 1 addition & 5 deletions packages/core/ui/page/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -548,11 +548,7 @@ export class Page extends PageBase {
}

if (nativeParent && nativeChild) {
if (typeof atIndex !== 'number' || atIndex >= nativeParent.subviews.count) {
nativeParent.addSubview(nativeChild);
} else {
nativeParent.insertSubviewAtIndex(nativeChild, atIndex);
}
IOSHelper.insertSubview(nativeParent, nativeChild, atIndex);

return true;
}
Expand Down
Loading