Skip to content
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
6 changes: 3 additions & 3 deletions apps/automated/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"nativescript-theme-core": "file:../../node_modules/nativescript-theme-core"
},
"devDependencies": {
"@nativescript/android": "alpha",
"@nativescript/ios": "alpha",
"@nativescript/visionos": "~8.9.0",
"@nativescript/android": "~9.0.0",
"@nativescript/ios": "~9.0.0",
"@nativescript/visionos": "~9.0.0",
"@nativescript/vite": "file:../../dist/packages/vite",
"@nativescript/webpack": "file:../../dist/packages/webpack5",
"circular-dependency-plugin": "^5.2.2",
Expand Down
6 changes: 3 additions & 3 deletions apps/toolbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"nativescript-theme-core": "file:../../node_modules/nativescript-theme-core"
},
"devDependencies": {
"@nativescript/android": "alpha",
"@nativescript/ios": "alpha",
"@nativescript/visionos": "~8.9.0",
"@nativescript/android": "~9.0.0",
"@nativescript/ios": "~9.0.0",
"@nativescript/visionos": "~9.0.0",
"@nativescript/vite": "file:../../dist/packages/vite",
"@nativescript/webpack": "file:../../dist/packages/webpack5",
"typescript": "~5.8.0"
Expand Down
2 changes: 0 additions & 2 deletions apps/toolbox/src/split-view/split-view-secondary.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<ActionBar title="Secondary View" class="action-bar">
</ActionBar>
<!-- Secondary column (detail) -->
<StackLayout class="p-16">
<Label text="Secondary" marginBottom="12" fontSize="22" fontWeight="bold" />
Expand Down
2 changes: 0 additions & 2 deletions apps/toolbox/src/split-view/split-view-supplement.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo" class="page">
<ActionBar title="Supplementary View" class="action-bar">
</ActionBar>
<!-- Supplementary column (detail) -->
<StackLayout class="p-16">
<Label text="Supplementary" marginBottom="12" fontSize="22" fontWeight="bold" />
Expand Down
6 changes: 3 additions & 3 deletions apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
"nativescript-theme-core": "file:../../node_modules/nativescript-theme-core"
},
"devDependencies": {
"@nativescript/android": "alpha",
"@nativescript/ios": "alpha",
"@nativescript/visionos": "~8.9.0",
"@nativescript/android": "~9.0.0",
"@nativescript/ios": "~9.0.0",
"@nativescript/visionos": "~9.0.0",
"@nativescript/webpack": "file:../../dist/packages/webpack5",
"typescript": "~5.8.0"
},
Expand Down
82 changes: 72 additions & 10 deletions packages/core/ui/split-view/index.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { SplitViewBase, displayModeProperty, splitBehaviorProperty, preferredPri
import { View } from '../core/view';
import { layout } from '../../utils';
import { SDK_VERSION } from '../../utils/constants';
import { FrameBase } from '../frame/frame-common';
import type { SplitRole } from '.';

@NativeClass
Expand Down Expand Up @@ -93,6 +94,37 @@ export class SplitView extends SplitViewBase {
return this.viewController.view;
}

onLoaded(): void {
super.onLoaded();
// Ensure proper view controller containment
this._ensureViewControllerContainment();
}

private _ensureViewControllerContainment(): void {
if (!this.viewController) {
return;
}

const window = this.nativeViewProtected?.window;

if (!window) {
return;
}

const currentRootVC = window.rootViewController;

// If the window's rootViewController is not our SplitViewController,
// we need to set it up properly
if (currentRootVC !== this.viewController) {
// Check if we can become the root view controller
// or if we need to be added as a child
if (currentRootVC) {
currentRootVC.addChildViewController(this.viewController);
this.viewController.didMoveToParentViewController(currentRootVC);
}
}
}

disposeNativeView(): void {
super.disposeNativeView();
this._controllers.clear();
Expand Down Expand Up @@ -256,6 +288,36 @@ export class SplitView extends SplitViewBase {
return wrapper;
}

private _attachSecondaryDisplayModeButton(): void {
const secondary = this._controllers.get('secondary');
if (!(secondary instanceof UINavigationController)) {
return;
}

const targetVC = secondary.topViewController;
if (!targetVC) {
// Subscribe to Frame's navigatedTo event to know when the first page is shown
const frameChild = this._children.get('secondary') as any;
if (frameChild && frameChild.on && !frameChild._splitViewSecondaryNavigatedHandler) {
frameChild._splitViewSecondaryNavigatedHandler = () => {
// Use setTimeout to ensure the navigation controller's topViewController is updated
setTimeout(() => this._attachSecondaryDisplayModeButton(), 0);
};
frameChild.on(FrameBase.navigatedToEvent, frameChild._splitViewSecondaryNavigatedHandler);
}
return;
}

// Avoid duplicates
if (targetVC.navigationItem.leftBarButtonItem) {
return;
}

// Set the displayModeButtonItem on the page's navigationItem
targetVC.navigationItem.leftBarButtonItem = this.viewController.displayModeButtonItem;
targetVC.navigationItem.leftItemsSupplementBackButton = true;
}

private _attachInspectorButton(): void {
const inspector = this._controllers.get('inspector');
if (!(inspector instanceof UINavigationController)) {
Expand All @@ -264,14 +326,14 @@ export class SplitView extends SplitViewBase {

const targetVC = inspector.topViewController;
if (!targetVC) {
// Subscribe to Frame event to know when the top VC is shown, then attach the button.
// Can only attach buttons once VC is available
// Subscribe to Frame's navigatedTo event to know when the first page is shown
const frameChild = this._children.get('inspector') as any;
if (frameChild && frameChild.on && !frameChild._inspectorVCShownHandler) {
frameChild._inspectorVCShownHandler = () => {
setTimeout(() => this._attachInspectorButton());
if (frameChild && frameChild.on && !frameChild._splitViewNavigatedHandler) {
frameChild._splitViewNavigatedHandler = () => {
// Use setTimeout to ensure the navigation controller's topViewController is updated
setTimeout(() => this._attachInspectorButton(), 0);
};
frameChild.on('viewControllerShown', frameChild._inspectorVCShownHandler.bind(this));
frameChild.on(FrameBase.navigatedToEvent, frameChild._splitViewNavigatedHandler);
}
return;
}
Expand Down Expand Up @@ -365,10 +427,10 @@ export class SplitView extends SplitViewBase {
const secondary = this._controllers.get('secondary');
const supplementary = this._controllers.get('supplementary');
const inspector = this._controllers.get('inspector');
if (secondary instanceof UINavigationController && secondary.navigationItem) {
// TODO: can add properties to customize this
secondary.navigationItem.leftBarButtonItem = this.viewController.displayModeButtonItem;
secondary.navigationItem.leftItemsSupplementBackButton = true;

// Attach displayModeButtonItem to the secondary column's first page
if (secondary instanceof UINavigationController) {
this._attachSecondaryDisplayModeButton();
}
if (supplementary) {
this.showSupplementary();
Expand Down
Loading