|
| 1 | +--- |
| 2 | +title: SplitView |
| 3 | +description: A singular root view component for coordinating up to four column roles (primary, secondary, supplementary, inspector). |
| 4 | +contributors: |
| 5 | + - NathanWalker |
| 6 | +--- |
| 7 | + |
| 8 | +`<SplitView>` is an iOS-only container component that gives you a declarative [UISplitViewController](https://developer.apple.com/documentation/uikit/uisplitviewcontroller) and exposes its modern multi-column capabilities to NativeScript apps. It lets you coordinate **up to four** roles: |
| 9 | + |
| 10 | +- **primary** – main navigation or master content |
| 11 | +- **secondary** – detail view for the selected item |
| 12 | +- **supplementary** – contextual / side content |
| 13 | +- **inspector** – tool / inspector pane available on iOS 17+ when the system supports it |
| 14 | + |
| 15 | +Each role is typically provided by a child `<Frame>` so that every column can manage its own navigation stack independently, while still being part of the same split view controller. This mirrors how native iPadOS apps structure complex layouts. |
| 16 | + |
| 17 | +::: tip |
| 18 | +It is intended to be used as the singular starting root view for the entire app. |
| 19 | + |
| 20 | +This component is ideal for iPadOS-style apps, admin-style layouts, or any experience where you need a master-detail flow plus an extra contextual pane or inspector. |
| 21 | +::: |
| 22 | + |
| 23 | +## Example |
| 24 | + |
| 25 | +### Declarative XML |
| 26 | + |
| 27 | +```xml |
| 28 | +<SplitView |
| 29 | + displayMode="twoBesideSecondary" |
| 30 | + splitBehavior="tile" |
| 31 | + preferredPrimaryColumnWidthFraction="0.25" |
| 32 | + preferredSupplementaryColumnWidthFraction="0.33" |
| 33 | + preferredInspectorColumnWidthFraction="0.20"> |
| 34 | + |
| 35 | + <Frame splitRole="primary" defaultPage="pages/master" /> |
| 36 | + <Frame splitRole="secondary" defaultPage="pages/detail" /> |
| 37 | + <Frame splitRole="supplementary" defaultPage="pages/context" /> |
| 38 | + <Frame splitRole="inspector" defaultPage="pages/inspector" /> |
| 39 | +</SplitView> |
| 40 | +``` |
| 41 | +This configures a 3–4 column layout (depending on OS support) and assigns each role to its own frame. |
| 42 | + |
| 43 | +### Programmatic |
| 44 | + |
| 45 | +```ts |
| 46 | +import { SplitView } from '@nativescript/core' |
| 47 | + |
| 48 | +const splitView = new SplitView() |
| 49 | +splitView.displayMode = 'twoBesideSecondary' |
| 50 | +splitView.splitBehavior = 'tile' |
| 51 | +splitView.preferredPrimaryColumnWidthFraction = 0.25 |
| 52 | + |
| 53 | +// create frames with splitRole before adding them |
| 54 | +``` |
| 55 | + |
| 56 | +### With inspector change listener |
| 57 | + |
| 58 | +```ts |
| 59 | +splitView.on('inspectorChange', ({ data }) => { |
| 60 | + console.log('Inspector visible?', data.showing) |
| 61 | +}) |
| 62 | +``` |
| 63 | +Fired whenever the inspector column is shown or hidden. |
| 64 | + |
| 65 | +## Concepts |
| 66 | + |
| 67 | +### Roles |
| 68 | + |
| 69 | +SplitView coordinates **roles** rather than arbitrary children. Children declare their intended role: |
| 70 | + |
| 71 | +```xml |
| 72 | +<Frame splitRole="primary" /> |
| 73 | +<Frame splitRole="secondary" /> |
| 74 | +<Frame splitRole="supplementary" /> |
| 75 | +<Frame splitRole="inspector" /> |
| 76 | +``` |
| 77 | + |
| 78 | +If a role is omitted, SplitView falls back to the order in which children were added. However, declaring the role is recommended for clarity and for future layout changes. |
| 79 | + |
| 80 | +### Column styles |
| 81 | + |
| 82 | +The underlying controller can operate in *double* or *triple* column styles. SplitView exposes this through a common enum: |
| 83 | + |
| 84 | +- `SplitView.SplitStyle.double` |
| 85 | +- `SplitView.SplitStyle.triple` |
| 86 | + |
| 87 | +iOS chooses the right `UISplitViewControllerStyle` for you. On iOS 17+ an inspector column can also be shown. citeturn2view0 |
| 88 | + |
| 89 | +## Props |
| 90 | + |
| 91 | +### displayMode |
| 92 | + |
| 93 | +```ts |
| 94 | +displayMode: |
| 95 | + | 'automatic' |
| 96 | + | 'secondaryOnly' |
| 97 | + | 'oneBesideSecondary' |
| 98 | + | 'oneOverSecondary' |
| 99 | + | 'twoBesideSecondary' |
| 100 | + | 'twoOverSecondary' |
| 101 | + | 'twoDisplaceSecondary' |
| 102 | +``` |
| 103 | + |
| 104 | +Maps to [UISplitViewController.preferredDisplayMode]. Determines how the primary/supplementary columns relate to the secondary column (beside vs over vs displaced). |
| 105 | + |
| 106 | +### splitBehavior (iOS 14+) |
| 107 | + |
| 108 | +```ts |
| 109 | +splitBehavior: 'automatic' | 'tile' | 'overlay' | 'displace' |
| 110 | +``` |
| 111 | + |
| 112 | +Maps to [UISplitViewController.preferredSplitBehavior](https://developer.apple.com/documentation/uikit/uisplitviewcontroller/preferreddisplaymode). Controls how columns behave when the size class changes (for example overlaying instead of resizing). iOS 14 or newer is required. |
| 113 | + |
| 114 | +### preferredPrimaryColumnWidthFraction |
| 115 | + |
| 116 | +```ts |
| 117 | +preferredPrimaryColumnWidthFraction: number // 0..1 |
| 118 | +``` |
| 119 | + |
| 120 | +Fractional width for the primary column (for example `0.25` = 25%). |
| 121 | + |
| 122 | +### preferredSupplementaryColumnWidthFraction |
| 123 | + |
| 124 | +```ts |
| 125 | +preferredSupplementaryColumnWidthFraction: number // 0..1 |
| 126 | +``` |
| 127 | + |
| 128 | +Used in triple-column style to reserve width for the supplementary column. |
| 129 | + |
| 130 | +### preferredInspectorColumnWidthFraction |
| 131 | + |
| 132 | +```ts |
| 133 | +preferredInspectorColumnWidthFraction: number // 0..1 |
| 134 | +``` |
| 135 | + |
| 136 | +Width fraction for the inspector column, applied only when the platform supports the inspector role (iOS 17+). On earlier versions this is safely ignored. |
| 137 | + |
| 138 | +### inspectorShowing (readonly) |
| 139 | + |
| 140 | +```ts |
| 141 | +inspectorShowing: boolean |
| 142 | +``` |
| 143 | + |
| 144 | +Current visibility state of the inspector column. Helpful to sync UI buttons with the actual split view state. |
| 145 | + |
| 146 | +## Static members |
| 147 | + |
| 148 | +### SplitView.getInstance() |
| 149 | + |
| 150 | +```ts |
| 151 | +const active = SplitView.getInstance() |
| 152 | +``` |
| 153 | + |
| 154 | +Returns the last created SplitView instance, or `null` if none exists. This is a convenience for apps that only ever use a single SplitView and want to access it imperatively (for example, from a service). |
| 155 | + |
| 156 | +### SplitView.SplitStyle |
| 157 | + |
| 158 | +```ts |
| 159 | +const { SplitStyle } = SplitView |
| 160 | +``` |
| 161 | + |
| 162 | +Common enum representing double vs triple column styles. The iOS implementation maps this to the proper `UISplitViewController` style. |
| 163 | + |
| 164 | +## Methods |
| 165 | + |
| 166 | +### showPrimary() / hidePrimary() |
| 167 | + |
| 168 | +```ts |
| 169 | +splitView.showPrimary() |
| 170 | +splitView.hidePrimary() |
| 171 | +``` |
| 172 | + |
| 173 | +Shows or hides the primary column. Useful on compact width or when presenting master-detail flows modally. |
| 174 | + |
| 175 | +### showSecondary() / hideSecondary() |
| 176 | + |
| 177 | +```ts |
| 178 | +splitView.showSecondary() |
| 179 | +splitView.hideSecondary() |
| 180 | +``` |
| 181 | + |
| 182 | +Controls the visibility of the secondary column. |
| 183 | + |
| 184 | +### showSupplementary() |
| 185 | + |
| 186 | +```ts |
| 187 | +splitView.showSupplementary() |
| 188 | +``` |
| 189 | + |
| 190 | +Ensures the supplementary column is visible when the display mode allows it. Hiding is typically handled automatically by the display mode. |
| 191 | + |
| 192 | +### showInspector() / hideInspector() |
| 193 | + |
| 194 | +```ts |
| 195 | +splitView.showInspector() |
| 196 | +splitView.hideInspector() |
| 197 | +``` |
| 198 | + |
| 199 | +Toggles the inspector column (iOS 17+). Calls are no-ops on platforms/versions where inspector is not available. |
| 200 | + |
| 201 | +### onSecondaryViewCollapsed(secondaryVC, primaryVC) |
| 202 | + |
| 203 | +Lifecycle hook invoked when the system collapses the secondary onto the primary (for example, when moving to a compact size). Override in subclasses or listen at the NativeScript level to adjust your UI. |
| 204 | + |
| 205 | +## Events |
| 206 | + |
| 207 | +### inspectorChange |
| 208 | + |
| 209 | +```ts |
| 210 | +splitView.on('inspectorChange', (args) => { |
| 211 | + console.log('Inspector visible?', args.data.showing) |
| 212 | +}) |
| 213 | +``` |
| 214 | + |
| 215 | +Emitted whenever the inspector column changes visibility. Payload contains a `data.showing: boolean`. |
| 216 | + |
| 217 | +## Platform notes |
| 218 | + |
| 219 | +- **Platform**: iOS only (backed by `UISplitViewController`). |
| 220 | +- **splitBehavior**: requires iOS 14+. |
| 221 | +- **Inspector**: requires iOS 17+. On earlier versions the property is ignored and inspector-related methods are safe no-ops. |
| 222 | + |
| 223 | +## Native component |
| 224 | + |
| 225 | +- iOS: [`UISplitViewController`](https://developer.apple.com/documentation/uikit/uisplitviewcontroller) |
0 commit comments