Skip to content

Commit f74a1f0

Browse files
douglowdert0maboro
andauthored
fix(iOS): fix tvOS compilation in split-view (#3590)
## Description Fix errors found in compiling screens for tvOS ## Changes Small changes in the split view classes. ## Test plan SDK 55 preview test app at https://github.com/douglowder/SDK55TV ## Checklist - [x] Included code example that can be used to test this change. - [ ] Updated / created local changelog entries in relevant test files. - [ ] For visual changes, included screenshots / GIFs / recordings documenting the change. - [ ] For API changes, updated relevant public types. - [x] Ensured that CI passes --------- Co-authored-by: Tomasz Boroń <tomasz.boron@swmansion.com>
1 parent ce44512 commit f74a1f0

3 files changed

Lines changed: 51 additions & 32 deletions

File tree

ios/gamma/split-view/RNSSplitViewAppearanceApplicator.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ class RNSSplitViewAppearanceApplicator {
6565
// Step 1 - general settings
6666
splitViewController.displayModeButtonVisibility = splitView.displayModeButtonVisibility
6767
splitViewController.preferredSplitBehavior = splitView.preferredSplitBehavior
68-
splitViewController.primaryBackgroundStyle = splitView.primaryBackgroundStyle
68+
#if !os(tvOS)
69+
splitViewController.primaryBackgroundStyle = splitView.primaryBackgroundStyle
70+
#endif
6971
splitViewController.presentsWithGesture = splitView.presentsWithGesture
7072
splitViewController.primaryEdge = splitView.primaryEdge
7173
splitViewController.showsSecondaryOnlyButton = splitView.showSecondaryToggleButton
@@ -79,7 +81,7 @@ class RNSSplitViewAppearanceApplicator {
7981
minWidth: splitView.minimumSupplementaryColumnWidth,
8082
maxWidth: splitView.maximumSupplementaryColumnWidth)
8183

82-
#if compiler(>=6.2)
84+
#if compiler(>=6.2) && !os(tvOS)
8385
if #available(iOS 26.0, *) {
8486
validateColumnConstraints(
8587
minWidth: splitView.minimumInspectorColumnWidth,
@@ -126,7 +128,7 @@ class RNSSplitViewAppearanceApplicator {
126128
splitView.preferredSupplementaryColumnWidthOrFraction
127129
}
128130

129-
#if compiler(>=6.2)
131+
#if compiler(>=6.2) && !os(tvOS)
130132
if #available(iOS 26.0, *) {
131133
if splitView.minimumSecondaryColumnWidth >= 0 {
132134
splitViewController.minimumSecondaryColumnWidth = splitView.minimumSecondaryColumnWidth

ios/gamma/split-view/RNSSplitViewHostController.swift

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,16 @@ extension RNSSplitViewHostController: RNSSplitViewNavigationControllerViewFrameO
399399
/// @param inspectors An array of inspector-type RNSSplitViewScreenComponentView subviews.
400400
///
401401
func maybeSetupInspector(_ inspectors: [RNSSplitViewScreenComponentView]) {
402-
403-
if #available(iOS 26.0, *) {
404-
let inspector = inspectors.first
405-
if inspector != nil {
406-
let inspectorViewController = RNSSplitViewNavigationController(
407-
rootViewController: inspector!.controller)
408-
setViewController(inspectorViewController, for: .inspector)
402+
#if !os(tvOS)
403+
if #available(iOS 26.0, *) {
404+
let inspector = inspectors.first
405+
if inspector != nil {
406+
let inspectorViewController = RNSSplitViewNavigationController(
407+
rootViewController: inspector!.controller)
408+
setViewController(inspectorViewController, for: .inspector)
409+
}
409410
}
410-
}
411+
#endif
411412
}
412413

413414
///
@@ -417,9 +418,11 @@ extension RNSSplitViewHostController: RNSSplitViewNavigationControllerViewFrameO
417418
/// Uses the UISplitViewController's new API introduced in iOS 26 to show the inspector column.
418419
///
419420
func maybeShowInspector() {
420-
if #available(iOS 26.0, *) {
421-
show(.inspector)
422-
}
421+
#if !os(tvOS)
422+
if #available(iOS 26.0, *) {
423+
show(.inspector)
424+
}
425+
#endif
423426
}
424427

425428
///
@@ -429,9 +432,11 @@ extension RNSSplitViewHostController: RNSSplitViewNavigationControllerViewFrameO
429432
/// Uses the UISplitViewController's new API introduced in iOS 26 to hide the inspector column.
430433
///
431434
func maybeHideInspector() {
432-
if #available(iOS 26.0, *) {
433-
hide(.inspector)
434-
}
435+
#if !os(tvOS)
436+
if #available(iOS 26.0, *) {
437+
hide(.inspector)
438+
}
439+
#endif
435440
}
436441
}
437442
#endif
@@ -469,23 +474,27 @@ extension RNSSplitViewHostController: UISplitViewControllerDelegate {
469474
public func splitViewController(
470475
_ svc: UISplitViewController, didHide column: UISplitViewController.Column
471476
) {
472-
if #available(iOS 26.0, *) {
473-
// TODO: we may consider removing this logic, because it could be handled by onViewDidDisappear on the column level
474-
// On the other hand, maybe dedicated event related to the inspector would be a better approach.
475-
// For now I am leaving it, but feel free to drop this method if there's any reason that `onDidDisappear` works better.
476-
if column != .inspector {
477-
return
478-
}
477+
#if !os(tvOS)
478+
if #available(iOS 26.0, *) {
479+
// TODO: we may consider removing this logic, because it could be handled by onViewDidDisappear on the column level
480+
// On the other hand, maybe dedicated event related to the inspector would be a better approach.
481+
// For now I am leaving it, but feel free to drop this method if there's any reason that `onDidDisappear` works better.
482+
483+
if column != .inspector {
484+
return
485+
}
479486

480-
// `didHide` for modal is called on finger down for dismiss, what is problematic, because we can cancel dismissing modal.
481-
// In this scenario, the modal inspector might receive an invalid state and will deviate from the JS value.
482-
// Therefore, for event emissions, we need to ensure that the view was detached from the view hierarchy, by checking its window.
483-
if let inspectorViewController = viewController(for: .inspector) {
484-
if inspectorViewController.view.window == nil {
485-
reactEventEmitter.emitOnHideInspector()
487+
// `didHide` for modal is called on finger down for dismiss, what is problematic, because we can cancel dismissing modal.
488+
// In this scenario, the modal inspector might receive an invalid state and will deviate from the JS value.
489+
// Therefore, for event emissions, we need to ensure that the view was detached from the view hierarchy, by checking its window.
490+
if let inspectorViewController = viewController(for: .inspector) {
491+
if inspectorViewController.view.window == nil {
492+
reactEventEmitter.emitOnHideInspector()
493+
}
486494
}
495+
487496
}
488-
}
497+
#endif
489498
}
490499
#endif
491500

ios/gamma/split-view/RNSSplitViewScreenShadowStateProxy.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#import <React/RCTAssert.h>
55
#import <React/RCTConversions.h>
6+
#import <cxxreact/ReactNativeVersion.h>
67
#import <rnscreens/RNSSplitViewScreenShadowNode.h>
78

89
namespace react = facebook::react;
@@ -44,7 +45,14 @@ - (void)updateShadowStateWithFrame:(CGRect)frame
4445

4546
if (!CGRectEqualToRect(frame, _lastScheduledFrame)) {
4647
auto newState = react::RNSSplitViewScreenState{RCTSizeFromCGSize(frame.size), RCTPointFromCGPoint(frame.origin)};
47-
_state->updateState(std::move(newState), facebook::react::EventQueue::UpdateMode::unstable_Immediate);
48+
_state->updateState(
49+
std::move(newState)
50+
// TODO: @t0maboro - remove this compilation check once TVOSExample is upgraded to RN 82+
51+
#if REACT_NATIVE_VERSION_MINOR >= 82
52+
,
53+
facebook::react::EventQueue::UpdateMode::unstable_Immediate
54+
#endif
55+
);
4856

4957
_lastScheduledFrame = frame;
5058
}

0 commit comments

Comments
 (0)