From f991e54c4f5ff8eaedb4cd8bfd99a2015fa3de48 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Wed, 28 Jun 2023 10:12:49 +0200 Subject: [PATCH 01/26] Reinstall pods in FTE --- FabricTestExample/ios/Podfile.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/FabricTestExample/ios/Podfile.lock b/FabricTestExample/ios/Podfile.lock index 3cf0d056b8..e668c1bb82 100644 --- a/FabricTestExample/ios/Podfile.lock +++ b/FabricTestExample/ios/Podfile.lock @@ -1118,7 +1118,7 @@ PODS: - React-RCTText - ReactCommon/turbomodule/core - Yoga - - RNScreens (3.21.1): + - RNScreens (3.22.0): - RCT-Folly - RCTRequired - RCTTypeSafety @@ -1126,8 +1126,8 @@ PODS: - React-Codegen - React-RCTFabric - ReactCommon/turbomodule/core - - RNScreens/common (= 3.21.1) - - RNScreens/common (3.21.1): + - RNScreens/common (= 3.22.0) + - RNScreens/common (3.22.0): - RCT-Folly - RCTRequired - RCTTypeSafety @@ -1382,7 +1382,7 @@ SPEC CHECKSUMS: ReactCommon: 01b6643cfeef0d9078c8125378066d20cc34ddfe RNGestureHandler: d8224aad6d7081834ae6e6cf925397059485b69e RNReanimated: 3ce2aec600ad2ef47a5927abf2742329d7a190e9 - RNScreens: 4dc185270d6150c84f5a1ba8d381cf551adff86a + RNScreens: 9d61ea7595ba14c8ef38c010e1e918bcc51fc5c3 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 Yoga: 258bd5f6f188432f18cc3f854497f1cf6a0f21c1 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a From a15d63fdf4e00643e2437c3444ac7c6e0a0a2827 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Thu, 6 Jul 2023 10:41:26 +0200 Subject: [PATCH 02/26] Stash various changes (POSSIBLY TO REVERT) --- FabricTestExample/App.js | 2 +- FabricTestExample/src/Test1097.tsx | 4 ++-- TestsExample/App.js | 2 +- TestsExample/src/Test1097.tsx | 6 +++--- ios/RNSScreen.mm | 33 ++++++++++++++++++++++++++++-- ios/RNSScreenStackHeaderConfig.mm | 5 +++-- 6 files changed, 41 insertions(+), 11 deletions(-) diff --git a/FabricTestExample/App.js b/FabricTestExample/App.js index 26fdc433b3..03d8d26bc3 100644 --- a/FabricTestExample/App.js +++ b/FabricTestExample/App.js @@ -89,5 +89,5 @@ import Test1726 from './src/Test1726'; enableFreeze(true); export default function App() { - return ; + return ; } diff --git a/FabricTestExample/src/Test1097.tsx b/FabricTestExample/src/Test1097.tsx index 8c5a737932..89a49cd940 100644 --- a/FabricTestExample/src/Test1097.tsx +++ b/FabricTestExample/src/Test1097.tsx @@ -19,8 +19,8 @@ export default function App(): JSX.Element { diff --git a/TestsExample/App.js b/TestsExample/App.js index 9c1e0c5907..8d92f88490 100644 --- a/TestsExample/App.js +++ b/TestsExample/App.js @@ -92,5 +92,5 @@ import Test1791 from './src/Test1791'; enableFreeze(true); export default function App() { - return ; + return ; } diff --git a/TestsExample/src/Test1097.tsx b/TestsExample/src/Test1097.tsx index 799235897d..3d07486ffb 100644 --- a/TestsExample/src/Test1097.tsx +++ b/TestsExample/src/Test1097.tsx @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ +/* eslint-disable react-hooks/exhaustive-deps */ import * as React from 'react'; import {Button, NativeSyntheticEvent, ScrollView} from 'react-native'; import { @@ -19,8 +19,8 @@ export default function App(): JSX.Element { diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index d6975f7850..90d1fb7978 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -8,6 +8,7 @@ #import #import #import +#import #import #import #import @@ -26,7 +27,7 @@ @interface RNSScreenView () #ifdef RCT_NEW_ARCH_ENABLED - + #else #endif @@ -581,11 +582,34 @@ - (void)updatePresentationStyle - (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index { - [super mountChildComponentView:childComponentView index:index]; if ([childComponentView isKindOfClass:[RNSScreenStackHeaderConfig class]]) { _config = childComponentView; ((RNSScreenStackHeaderConfig *)childComponentView).screenView = self; } + if ([childComponentView isKindOfClass:[RCTViewComponentView class]]) { + // If the scroll view is present: + if (_reactSubviews.count > 0 && [_reactSubviews[0] isKindOfClass:[RCTScrollViewComponentView class]]) { + NSLog(@"FOUND THE SCROLL VIEW"); + } + } + if ([childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { + // if ((RNSScreenStackHeaderConfig *)self.config != nil) { + // } + RCTScrollViewComponentView *scrollView = childComponentView; + if (scrollView.scrollViewDelegateSplitter != nil) { + [scrollView.scrollViewDelegateSplitter addDelegate:self]; + } else { + NSLog(@"ScrollView's delegate is nil"); + } + + [[_reactSubviews lastObject] mountChildComponentView:childComponentView index:0]; + // index = index - 1; + // [self unmountChildComponentView:_reactSubviews.lastObject index:index]; + // [_reactSubviews removeLastObject]; + // NSLog(@"FOUND THE SCROLL VIEW (BEFORE RCTViewComponentView)"); + return; + } + [super mountChildComponentView:childComponentView index:index]; [_reactSubviews insertObject:childComponentView atIndex:index]; } @@ -598,6 +622,11 @@ - (void)unmountChildComponentView:(UIView *)childCompo [super unmountChildComponentView:childComponentView index:index]; } +- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView +{ + [self.controller.navigationController setNavigationBarHidden:YES animated:YES]; +} + #pragma mark - RCTComponentViewProtocol - (void)prepareForRecycle diff --git a/ios/RNSScreenStackHeaderConfig.mm b/ios/RNSScreenStackHeaderConfig.mm index a5eb013191..864951bfc8 100644 --- a/ios/RNSScreenStackHeaderConfig.mm +++ b/ios/RNSScreenStackHeaderConfig.mm @@ -66,7 +66,7 @@ - (instancetype)initWithFrame:(CGRect)frame if (self = [super initWithFrame:frame]) { static const auto defaultProps = std::make_shared(); _props = defaultProps; - _show = YES; + _show = NO; _translucent = NO; [self initProps]; } @@ -605,7 +605,8 @@ + (void)updateViewController:(UIViewController *)vc if (@available(iOS 11.0, *)) { RNSSearchBar *searchBar = subview.subviews[0]; navitem.searchController = searchBar.controller; - navitem.hidesSearchBarWhenScrolling = searchBar.hideWhenScrolling; + // navitem.hidesSearchBarWhenScrolling = searchBar.hideWhenScrolling; + navitem.hidesSearchBarWhenScrolling = true; } #endif } From d8a83a52b78e02e48c805aab35eec4e3785d57d5 Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Fri, 7 Jul 2023 11:05:53 +0200 Subject: [PATCH 03/26] Partially working non react-native setup --- FabricTestExample/src/Test1097.tsx | 28 +++++----- ios/RNSScreen.mm | 83 +++++++++++++++++++++--------- 2 files changed, 74 insertions(+), 37 deletions(-) diff --git a/FabricTestExample/src/Test1097.tsx b/FabricTestExample/src/Test1097.tsx index 89a49cd940..820533b775 100644 --- a/FabricTestExample/src/Test1097.tsx +++ b/FabricTestExample/src/Test1097.tsx @@ -42,20 +42,20 @@ function First({navigation}: NativeStackScreenProps) { const [search, setSearch] = React.useState(''); const searchBarOptions: SearchBarProps = { - // @ts-ignore - ref: searchBarRef, - barTintColor: 'powderblue', - hideWhenScrolling: true, - obscureBackground: false, - hideNavigationBar: false, - autoCapitalize: 'sentences', - placeholder: 'Some text', - onChangeText: (e: NativeSyntheticEvent<{text: string}>) => - setSearch(e.nativeEvent.text), - onCancelButtonPress: () => console.warn('Cancel button pressed'), - onSearchButtonPress: () => console.warn('Search button pressed'), - onFocus: () => console.warn('onFocus event'), - onBlur: () => console.warn('onBlur event'), + // // @ts-ignore + // ref: searchBarRef, + // barTintColor: 'powderblue', + // hideWhenScrolling: true, + // obscureBackground: false, + // hideNavigationBar: false, + // autoCapitalize: 'sentences', + // placeholder: 'Some text', + // onChangeText: (e: NativeSyntheticEvent<{text: string}>) => + // setSearch(e.nativeEvent.text), + // onCancelButtonPress: () => console.warn('Cancel button pressed'), + // onSearchButtonPress: () => console.warn('Search button pressed'), + // onFocus: () => console.warn('onFocus event'), + // onBlur: () => console.warn('onBlur event'), }; const items = [ diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index 90d1fb7978..5a893f394b 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -6,6 +6,7 @@ #ifdef RCT_NEW_ARCH_ENABLED #import +#import #import #import #import @@ -46,6 +47,39 @@ @implementation RNSScreenView { #endif } +#ifdef RCT_NEW_ARCH_ENABLED +- (void)attachScrollView +{ + if ([[self subviews] count] == 0) { + CGRect frame = CGRectMake(0, 0, 390, 701); + // UIScrollView *scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:frame]; + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; + // scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + //(0 143; 390 701) + // Initialize UIViews (test rectangles) to add to the UIScrollView + for (int i = 0; i < 10; i++) { + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; + view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; + [scrollView addSubview:view]; + } + // Set the content size of the UIScrollView + scrollView.contentSize = CGSizeMake(frame.size.width, 10 * 100); + [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; + + // Add the UIScrollView to the given view + [self addSubview:scrollView]; + + UINavigationItem *navItem = [[self controller] navigationController].navigationItem; + + if (navItem == nil) { + NSLog(@"NavItem is nil"); + } else { + navItem.hidesSearchBarWhenScrolling = false; + } + } +} +#endif + #ifdef RCT_NEW_ARCH_ENABLED - (instancetype)initWithFrame:(CGRect)frame { @@ -54,8 +88,9 @@ - (instancetype)initWithFrame:(CGRect)frame _props = defaultProps; _reactSubviews = [NSMutableArray new]; [self initCommonProps]; + [self setFrame:CGRectMake(0, 0, 390, 701)]; + [self attachScrollView]; } - return self; } #endif // RCT_NEW_ARCH_ENABLED @@ -585,32 +620,34 @@ - (void)mountChildComponentView:(UIView *)childCompone if ([childComponentView isKindOfClass:[RNSScreenStackHeaderConfig class]]) { _config = childComponentView; ((RNSScreenStackHeaderConfig *)childComponentView).screenView = self; + [_reactSubviews insertObject:childComponentView atIndex:index]; } - if ([childComponentView isKindOfClass:[RCTViewComponentView class]]) { - // If the scroll view is present: - if (_reactSubviews.count > 0 && [_reactSubviews[0] isKindOfClass:[RCTScrollViewComponentView class]]) { - NSLog(@"FOUND THE SCROLL VIEW"); - } - } - if ([childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { - // if ((RNSScreenStackHeaderConfig *)self.config != nil) { + // [self attachScrollView]; + if (![childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { + // if (_reactSubviews.count > 0 && [_reactSubviews[0] isKindOfClass:[RCTScrollViewComponentView class]]) { + // NSLog(@"FOUND THE SCROLL VIEW"); // } - RCTScrollViewComponentView *scrollView = childComponentView; - if (scrollView.scrollViewDelegateSplitter != nil) { - [scrollView.scrollViewDelegateSplitter addDelegate:self]; - } else { - NSLog(@"ScrollView's delegate is nil"); - } - - [[_reactSubviews lastObject] mountChildComponentView:childComponentView index:0]; - // index = index - 1; - // [self unmountChildComponentView:_reactSubviews.lastObject index:index]; - // [_reactSubviews removeLastObject]; - // NSLog(@"FOUND THE SCROLL VIEW (BEFORE RCTViewComponentView)"); return; } - [super mountChildComponentView:childComponentView index:index]; - [_reactSubviews insertObject:childComponentView atIndex:index]; + // if ([childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { + // RCTScrollViewComponentView *scrollView = (RCTScrollViewComponentView *)childComponentView; + // if (scrollView.scrollViewDelegateSplitter != nil) { + // [scrollView.scrollViewDelegateSplitter addDelegate:self]; + // } else { + // NSLog(@"ScrollView's delegate is nil"); + // } + // + // [[_reactSubviews lastObject] mountChildComponentView:childComponentView index:0]; + // // index = index - 1; + // // [self unmountChildComponentView:_reactSubviews.lastObject index:index]; + // // [_reactSubviews removeLastObject]; + // // NSLog(@"FOUND THE SCROLL VIEW (BEFORE RCTViewComponentView)"); + // return; + // } + return; + childComponentView.frame = CGRectMake(0, 0, 390, 701); + [super mountChildComponentView:childComponentView index:0]; + [_reactSubviews insertObject:childComponentView atIndex:0]; } - (void)unmountChildComponentView:(UIView *)childComponentView index:(NSInteger)index From 32a8d9a9ec121022c78809e8edd69aa6e7b8315c Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Fri, 7 Jul 2023 11:06:09 +0200 Subject: [PATCH 04/26] Fully working non react-native setup --- ios/RNSScreen.h | 1 + ios/RNSScreen.mm | 14 ++--- ios/RNSScreenStack.mm | 120 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 7 deletions(-) diff --git a/ios/RNSScreen.h b/ios/RNSScreen.h index c0b00abf9a..a10c996b53 100644 --- a/ios/RNSScreen.h +++ b/ios/RNSScreen.h @@ -108,6 +108,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)notifyDisappear; - (void)updateBounds; - (void)notifyDismissedWithCount:(int)dismissCount; +- (instancetype)initWithFrame:(CGRect)frame; #endif - (void)notifyTransitionProgress:(double)progress closing:(BOOL)closing goingForward:(BOOL)goingForward; diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index 5a893f394b..559fcb3948 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -69,13 +69,13 @@ - (void)attachScrollView // Add the UIScrollView to the given view [self addSubview:scrollView]; - UINavigationItem *navItem = [[self controller] navigationController].navigationItem; - - if (navItem == nil) { - NSLog(@"NavItem is nil"); - } else { - navItem.hidesSearchBarWhenScrolling = false; - } + // UINavigationItem *navItem = [[self controller] navigationController].navigationItem; + // + // if (navItem == nil) { + // NSLog(@"NavItem is nil"); + // } else { + // navItem.hidesSearchBarWhenScrolling = false; + // } } } #endif diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index e97011e70e..388ad1109d 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -70,6 +70,53 @@ - (UIViewController *)childViewControllerForHomeIndicatorAutoHidden } #endif +- (void)willMoveToParentViewController:(UIViewController *)parent +{ + NSLog(@"RNSScreensNavigationController will move to parent view controller %@\n", parent); +} + +- (void)didMoveToParentViewController:(UIViewController *)parent +{ + NSLog(@"RNSScreensNavigationController did move to parent view controller %@\n", parent); +} + +- (void)viewDidAppear:(BOOL)animated +{ + NSLog(@"RNSScreensNavigationController view %@ did appear\n", self.view); + UIViewController *viewController = [UIViewController new]; + UIScrollView *scrollView = [self getScrollView]; + [viewController setView:scrollView]; + + // Configure navigation item + NSLog(@"New vc's navigation item: %@\n", viewController.navigationItem); + viewController.navigationItem.title = @"NavItem title"; + viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + // viewController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways; + self.navigationBar.prefersLargeTitles = YES; + viewController.navigationItem.searchController = [UISearchController new]; + + [self pushViewController:viewController animated:YES]; +} + +- (UIScrollView *)getScrollView +{ + CGRect frame = CGRectMake(0, 0, 390, 701); + // UIScrollView *scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:frame]; + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; + // scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + //(0 143; 390 701) + // Initialize UIViews (test rectangles) to add to the UIScrollView + for (int i = 0; i < 10; i++) { + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; + view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; + [scrollView addSubview:view]; + } + // Set the content size of the UIScrollView + scrollView.contentSize = CGSizeMake(frame.size.width, 10 * 100); + [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; + return scrollView; +} + @end #if !TARGET_OS_TV @@ -943,6 +990,58 @@ - (void)didUpdateReactSubviews #ifdef RCT_NEW_ARCH_ENABLED #pragma mark - Fabric specific +- (void)attachScrollView +{ + if ([[self subviews] count] == 0) { + UIScrollView *scrollView = [self getScrollView]; + // CGRect frame = CGRectMake(0, 0, 390, 701); + // // UIScrollView *scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:frame]; + // UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; + // // scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + // //(0 143; 390 701) + // // Initialize UIViews (test rectangles) to add to the UIScrollView + // for (int i = 0; i < 10; i++) { + // UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; + // view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; + // [scrollView addSubview:view]; + // } + // // Set the content size of the UIScrollView + // scrollView.contentSize = CGSizeMake(frame.size.width, 10 * 100); + // [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; + + // Add the UIScrollView to the given view + + [self addSubview:scrollView]; + + // UINavigationItem *navItem = [[self controller] navigationController].navigationItem; + // + // if (navItem == nil) { + // NSLog(@"NavItem is nil"); + // } else { + // navItem.hidesSearchBarWhenScrolling = false; + // } + } +} + +- (UIScrollView *)getScrollView +{ + CGRect frame = CGRectMake(0, 0, 390, 701); + // UIScrollView *scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:frame]; + UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; + // scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + //(0 143; 390 701) + // Initialize UIViews (test rectangles) to add to the UIScrollView + for (int i = 0; i < 10; i++) { + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; + view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; + [scrollView addSubview:view]; + } + // Set the content size of the UIScrollView + scrollView.contentSize = CGSizeMake(frame.size.width, 10 * 100); + [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; + return scrollView; +} + - (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index { if (![childComponentView isKindOfClass:[RNSScreenView class]]) { @@ -950,6 +1049,27 @@ - (void)mountChildComponentView:(UIView *)childCompone return; } + if ([[self subviews] count] > 0) { + return; + } + + // UIViewController *viewController = [UIViewController new]; + // UIScrollView *scrollView = [self getScrollView]; + // [viewController setView:scrollView]; + // + // [_controller pushViewController:viewController animated:YES]; + + // [self attachScrollView]; + // [self reactAddControllerToClosestParent:_controller]; + // dispatch_async(dispatch_get_main_queue(), ^{ + // [self maybeAddToParentAndUpdateContainer]; + // }); + + // RNSScreenView *screenView = [[RNSScreenView alloc] initWithFrame:CGRectMake(0, 0, 390, 701)]; + // [self addSubview:screenView]; + // [self attachScrollView]; + return; + RCTAssert( childComponentView.reactSuperview == nil, @"Attempt to mount already mounted component view. (parent: %@, child: %@, index: %@, existing parent: %@)", From cd6153d104d828abc474c0f8e657cb562610c7ca Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Tue, 11 Jul 2023 19:31:42 +0200 Subject: [PATCH 05/26] Stash experiments --- ios/RNSScreen.mm | 47 ++++--- ios/RNSScreenNavigationContainer.mm | 2 +- ios/RNSScreenStack.mm | 207 ++++++++++++++++++++++++++-- ios/RNSScreenStackHeaderConfig.h | 1 + ios/RNSScreenStackHeaderConfig.mm | 15 +- 5 files changed, 242 insertions(+), 30 deletions(-) diff --git a/ios/RNSScreen.mm b/ios/RNSScreen.mm index 559fcb3948..38a74dd061 100644 --- a/ios/RNSScreen.mm +++ b/ios/RNSScreen.mm @@ -88,8 +88,8 @@ - (instancetype)initWithFrame:(CGRect)frame _props = defaultProps; _reactSubviews = [NSMutableArray new]; [self initCommonProps]; - [self setFrame:CGRectMake(0, 0, 390, 701)]; - [self attachScrollView]; + // [self setFrame:CGRectMake(0, 0, 390, 701)]; + // [self attachScrollView]; } return self; } @@ -617,18 +617,28 @@ - (void)updatePresentationStyle - (void)mountChildComponentView:(UIView *)childComponentView index:(NSInteger)index { + /// Original implementation + // [super mountChildComponentView:childComponentView index:index]; + // if ([childComponentView isKindOfClass:[RNSScreenStackHeaderConfig class]]) { + // _config = childComponentView; + // ((RNSScreenStackHeaderConfig *)childComponentView).screenView = self; + // } + // [_reactSubviews insertObject:childComponentView atIndex:index]; + // return; + //////////////////////////////////////////////////// + if ([childComponentView isKindOfClass:[RNSScreenStackHeaderConfig class]]) { _config = childComponentView; ((RNSScreenStackHeaderConfig *)childComponentView).screenView = self; [_reactSubviews insertObject:childComponentView atIndex:index]; } // [self attachScrollView]; - if (![childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { - // if (_reactSubviews.count > 0 && [_reactSubviews[0] isKindOfClass:[RCTScrollViewComponentView class]]) { - // NSLog(@"FOUND THE SCROLL VIEW"); - // } - return; - } + // if (![childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { + // // if (_reactSubviews.count > 0 && [_reactSubviews[0] isKindOfClass:[RCTScrollViewComponentView class]]) { + // // NSLog(@"FOUND THE SCROLL VIEW"); + // // } + // return; + // } // if ([childComponentView isKindOfClass:[RCTScrollViewComponentView class]]) { // RCTScrollViewComponentView *scrollView = (RCTScrollViewComponentView *)childComponentView; // if (scrollView.scrollViewDelegateSplitter != nil) { @@ -644,8 +654,8 @@ - (void)mountChildComponentView:(UIView *)childCompone // // NSLog(@"FOUND THE SCROLL VIEW (BEFORE RCTViewComponentView)"); // return; // } - return; - childComponentView.frame = CGRectMake(0, 0, 390, 701); + // return; + // childComponentView.frame = CGRectMake(0, 0, 390, 701); [super mountChildComponentView:childComponentView index:0]; [_reactSubviews insertObject:childComponentView atIndex:0]; } @@ -659,10 +669,10 @@ - (void)unmountChildComponentView:(UIView *)childCompo [super unmountChildComponentView:childComponentView index:index]; } -- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView -{ - [self.controller.navigationController setNavigationBarHidden:YES animated:YES]; -} +//- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView +//{ +// [self.controller.navigationController setNavigationBarHidden:YES animated:YES]; +//} #pragma mark - RCTComponentViewProtocol @@ -1260,9 +1270,12 @@ - (void)hideHeaderIfNecessary if (wasSearchBarActive && shouldHideHeader) { dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 0); - dispatch_after(popTime, dispatch_get_main_queue(), ^(void) { - [self.navigationController setNavigationBarHidden:YES animated:NO]; - }); + dispatch_after( + popTime, + dispatch_get_main_queue(), + ^(void){ + // [self.navigationController setNavigationBarHidden:YES animated:NO]; + }); } } } diff --git a/ios/RNSScreenNavigationContainer.mm b/ios/RNSScreenNavigationContainer.mm index 0a07fe2fe3..678409ecf8 100644 --- a/ios/RNSScreenNavigationContainer.mm +++ b/ios/RNSScreenNavigationContainer.mm @@ -17,7 +17,7 @@ @implementation RNSScreenNavigationContainerView - (void)setupController { self.controller = [[RNScreensContainerNavigationController alloc] init]; - [(RNScreensContainerNavigationController *)self.controller setNavigationBarHidden:YES animated:NO]; + // [(RNScreensContainerNavigationController *)self.controller setNavigationBarHidden:YES animated:NO]; [self addSubview:self.controller.view]; } diff --git a/ios/RNSScreenStack.mm b/ios/RNSScreenStack.mm index 388ad1109d..b8d729238f 100644 --- a/ios/RNSScreenStack.mm +++ b/ios/RNSScreenStack.mm @@ -7,7 +7,9 @@ #import #import +#import #import +#import #else #import @@ -80,43 +82,226 @@ - (void)didMoveToParentViewController:(UIViewController *)parent NSLog(@"RNSScreensNavigationController did move to parent view controller %@\n", parent); } -- (void)viewDidAppear:(BOOL)animated +/// Works fine +- (void)expOnlyUIKit { - NSLog(@"RNSScreensNavigationController view %@ did appear\n", self.view); UIViewController *viewController = [UIViewController new]; - UIScrollView *scrollView = [self getScrollView]; + UIScrollView *scrollView = [self getUIKitScrollView]; + [viewController setView:scrollView]; + viewController.navigationItem.title = @"NavItem title"; + viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + viewController.navigationItem.searchController = [UISearchController new]; + self.navigationBar.prefersLargeTitles = YES; - // Configure navigation item - NSLog(@"New vc's navigation item: %@\n", viewController.navigationItem); + [self setViewControllers:@[ viewController ]]; +} + +/// Works fine +- (void)expVcUIKitAndReactScrollView +{ + UIViewController *viewController = [UIViewController new]; + RCTEnhancedScrollView *scrollView = [self getReactEnhancedScrollView]; + + [viewController setView:scrollView]; viewController.navigationItem.title = @"NavItem title"; viewController.navigationItem.hidesSearchBarWhenScrolling = YES; - // viewController.navigationItem.largeTitleDisplayMode = UINavigationItemLargeTitleDisplayModeAlways; + viewController.navigationItem.searchController = [UISearchController new]; self.navigationBar.prefersLargeTitles = YES; + + [self setViewControllers:@[ viewController ]]; +} + +/// Works fine +- (void)expVcUIKitAndFullReactSetup +{ + UIViewController *viewController = [UIViewController new]; + RCTScrollViewComponentView *scrollView = [self getReactRCTScrollViewComponentView]; + + [viewController setView:scrollView]; + viewController.navigationItem.title = @"NavItem title"; + viewController.navigationItem.hidesSearchBarWhenScrolling = YES; viewController.navigationItem.searchController = [UISearchController new]; + self.navigationBar.prefersLargeTitles = YES; - [self pushViewController:viewController animated:YES]; + [self setViewControllers:@[ viewController ]]; } -- (UIScrollView *)getScrollView +/// Works fine +- (void)expWithScreensVcAndReactScrollView +{ + RNSScreen *viewController = [[RNSScreen alloc] init]; + RCTEnhancedScrollView *scrollView = [self getReactEnhancedScrollView]; + [viewController setView:scrollView]; + + viewController.navigationItem.title = @"NavItem title"; + viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + viewController.navigationItem.searchController = [UISearchController new]; + self.navigationBar.prefersLargeTitles = YES; + + [self setViewControllers:@[ viewController ]]; +} + +/// Work fine +- (void)expWithScreensVcAndFullReactSetup +{ + RNSScreen *viewController = [[RNSScreen alloc] init]; + RCTScrollViewComponentView *scrollView = [self getReactRCTScrollViewComponentView]; + + [viewController setView:scrollView]; + viewController.navigationItem.title = @"NavItem title"; + viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + viewController.navigationItem.searchController = [UISearchController new]; + self.navigationBar.prefersLargeTitles = YES; + + [self setViewControllers:@[ viewController ]]; +} + +/// Works fine +- (void)expWithScreensVcAndIntermediateViewAndFullReactSetup +{ + RNSScreen *viewController = [[RNSScreen alloc] init]; + RCTScrollViewComponentView *scrollView = [self getReactRCTScrollViewComponentView]; + UIView *intermediateView = [UIView new]; + [intermediateView addSubview:scrollView]; + + [viewController setView:intermediateView]; + viewController.navigationItem.title = @"NavItem title"; + viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + viewController.navigationItem.searchController = [UISearchController new]; + self.navigationBar.prefersLargeTitles = YES; + + [self setViewControllers:@[ viewController ]]; +} + +/// Works fine +- (void)expWithPartialScreensSetupAndUIScrollView +{ + RNSScreenView *screenView = [[RNSScreenView alloc] init]; + // RNSScreen *viewController = [[RNSScreen alloc] init]; + RNSScreen *viewController = screenView.controller; + // screenView.controller = viewController; + + UIScrollView *scrollView = [self getUIKitScrollView]; + [screenView addSubview:scrollView]; + + // viewController.navigationItem.title = @"NavItem title"; + // viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + // viewController.navigationItem.searchController = [UISearchController new]; + // self.navigationBar.prefersLargeTitles = YES; + + [self setViewControllers:@[ viewController ]]; + // [self setNavigationBarHidden:NO]; +} + +/// Works fine +- (void)expWithPartialScreensSetupAndReactScrollView +{ + RNSScreenView *screenView = [[RNSScreenView alloc] init]; + RNSScreen *viewController = screenView.controller; + + RCTEnhancedScrollView *scrollView = [self getReactEnhancedScrollView]; + [screenView addSubview:scrollView]; + + [self setViewControllers:@[ viewController ]]; +} + +/// Works fine... +/// It indicates that the problem lays somewhere in configuration / configuration order? +- (void)expWithPartialScreensSetupAndReactFullSetup +{ + RNSScreenView *screenView = [[RNSScreenView alloc] init]; + RNSScreen *viewController = screenView.controller; + + RCTScrollViewComponentView *scrollView = [self getReactRCTScrollViewComponentView]; + [screenView addSubview:scrollView]; + + [self setViewControllers:@[ viewController ]]; +} + +- (void)viewDidAppear:(BOOL)animated +{ + NSLog(@"RNSScreensNavigationController view %@ did appear\n", self.view); + // [self expOnlyUIKit]; + // [self expVcUIKitAndReactScrollView]; + // [self expVcUIKitAndFullReactSetup]; + // [self expWithScreensVcAndReactScrollView]; + // [self expWithScreensVcAndFullReactSetup]; + // [self expWithScreensVcAndIntermediateViewAndFullReactSetup]; + // [self expWithPartialScreensSetupAndUIScrollView]; + // [self expWithPartialScreensSetupAndReactScrollView]; + // [self expWithPartialScreensSetupAndReactFullSetup]; + return; +} + +- (UIScrollView *)getUIKitScrollView { CGRect frame = CGRectMake(0, 0, 390, 701); - // UIScrollView *scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:frame]; UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; + + // Mimicing setup in RCTScrollViewComponentView + // UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero]; + // [scrollView addSubview:containerView]; + + // UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; // scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; //(0 143; 390 701) // Initialize UIViews (test rectangles) to add to the UIScrollView - for (int i = 0; i < 10; i++) { + int nItems{10}; + for (int i = 0; i < nItems; i++) { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; [scrollView addSubview:view]; + // [scrollView.subviews.firstObject addSubview:view]; } // Set the content size of the UIScrollView - scrollView.contentSize = CGSizeMake(frame.size.width, 10 * 100); + scrollView.contentSize = CGSizeMake(frame.size.width, nItems * 100); + [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; + return scrollView; +} + +- (RCTEnhancedScrollView *)getReactEnhancedScrollView +{ + CGRect frame = CGRectMake(0, 0, 390, 701); + UIScrollView *scrollView = [[RCTEnhancedScrollView alloc] initWithFrame:frame]; + + // Mimicing setup in RCTScrollViewComponentView + // UIView *containerView = [[UIView alloc] initWithFrame:CGRectZero]; + // [scrollView addSubview:containerView]; + + // UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:frame]; + // scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; + //(0 143; 390 701) + // Initialize UIViews (test rectangles) to add to the UIScrollView + int nItems{10}; + for (int i = 0; i < nItems; i++) { + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; + view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; + [scrollView addSubview:view]; + // [scrollView.subviews.firstObject addSubview:view]; + } + // Set the content size of the UIScrollView + scrollView.contentSize = CGSizeMake(frame.size.width, nItems * 100); [scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; return scrollView; } +- (RCTScrollViewComponentView *)getReactRCTScrollViewComponentView +{ + CGRect frame = CGRectMake(0, 0, 390, 701); + RCTScrollViewComponentView *scrollView = [[RCTScrollViewComponentView alloc] initWithFrame:frame]; + int nItems{10}; + for (int i = 0; i < nItems; i++) { + UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, i * 100, frame.size.width, 80)]; + view.backgroundColor = [UIColor colorWithRed:drand48() green:drand48() blue:drand48() alpha:1.0]; + [scrollView mountChildComponentView:view index:scrollView.subviews.count]; + // [scrollView addSubview:view]; + } + scrollView.scrollView.contentSize = CGSizeMake(frame.size.width, nItems * 100); + [scrollView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentAutomatic]; + return scrollView; +} + @end #if !TARGET_OS_TV diff --git a/ios/RNSScreenStackHeaderConfig.h b/ios/RNSScreenStackHeaderConfig.h index 83d4b61afe..19c506d038 100644 --- a/ios/RNSScreenStackHeaderConfig.h +++ b/ios/RNSScreenStackHeaderConfig.h @@ -26,6 +26,7 @@ #ifdef RCT_NEW_ARCH_ENABLED @property (nonatomic) BOOL show; +- (void)updateViewControllerIfNeeded; #else @property (nonatomic) UIBlurEffectStyle blurEffect; @property (nonatomic) BOOL hide; diff --git a/ios/RNSScreenStackHeaderConfig.mm b/ios/RNSScreenStackHeaderConfig.mm index 864951bfc8..7d2a4b03c4 100644 --- a/ios/RNSScreenStackHeaderConfig.mm +++ b/ios/RNSScreenStackHeaderConfig.mm @@ -450,6 +450,7 @@ + (void)updateViewController:(UIViewController *)vc withConfig:(RNSScreenStackHeaderConfig *)config animated:(BOOL)animated { + // return; UINavigationItem *navitem = vc.navigationItem; UINavigationController *navctr = (UINavigationController *)vc.parentViewController; @@ -463,6 +464,18 @@ + (void)updateViewController:(UIViewController *)vc #else BOOL shouldHide = config == nil || config.hide; #endif + shouldHide = NO; + + navitem.title = @"NavItem Title"; + navitem.hidesSearchBarWhenScrolling = YES; + navitem.searchController = [UISearchController new]; + [[navctr navigationBar] setPrefersLargeTitles:YES]; + + // viewController.navigationItem.title = @"NavItem title"; + // viewController.navigationItem.hidesSearchBarWhenScrolling = YES; + // viewController.navigationItem.searchController = [UISearchController new]; + // self.navigationBar.prefersLargeTitles = YES; + return; if (!shouldHide && !config.translucent) { // when nav bar is not translucent we chage edgesForExtendedLayout to avoid system laying out @@ -606,7 +619,7 @@ + (void)updateViewController:(UIViewController *)vc RNSSearchBar *searchBar = subview.subviews[0]; navitem.searchController = searchBar.controller; // navitem.hidesSearchBarWhenScrolling = searchBar.hideWhenScrolling; - navitem.hidesSearchBarWhenScrolling = true; + navitem.hidesSearchBarWhenScrolling = YES; } #endif } From 44620d2d0d306e690f2219e3ce070c09215e0adc Mon Sep 17 00:00:00 2001 From: Kacper Kafara Date: Fri, 14 Jul 2023 11:08:12 +0200 Subject: [PATCH 06/26] Update example in FTE --- FabricTestExample/src/Test1097.tsx | 42 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/FabricTestExample/src/Test1097.tsx b/FabricTestExample/src/Test1097.tsx index 820533b775..63b1ecb666 100644 --- a/FabricTestExample/src/Test1097.tsx +++ b/FabricTestExample/src/Test1097.tsx @@ -1,6 +1,5 @@ -/* eslint-disable @typescript-eslint/ban-ts-comment */ import * as React from 'react'; -import {Button, NativeSyntheticEvent, ScrollView} from 'react-native'; +import {Button, NativeSyntheticEvent, ScrollView, View} from 'react-native'; import { NavigationContainer, NavigationProp, @@ -19,8 +18,8 @@ export default function App(): JSX.Element { @@ -43,19 +42,19 @@ function First({navigation}: NativeStackScreenProps) { const searchBarOptions: SearchBarProps = { // // @ts-ignore - // ref: searchBarRef, - // barTintColor: 'powderblue', - // hideWhenScrolling: true, - // obscureBackground: false, - // hideNavigationBar: false, - // autoCapitalize: 'sentences', - // placeholder: 'Some text', - // onChangeText: (e: NativeSyntheticEvent<{text: string}>) => - // setSearch(e.nativeEvent.text), - // onCancelButtonPress: () => console.warn('Cancel button pressed'), - // onSearchButtonPress: () => console.warn('Search button pressed'), - // onFocus: () => console.warn('onFocus event'), - // onBlur: () => console.warn('onBlur event'), + ref: searchBarRef, + barTintColor: 'powderblue', + hideWhenScrolling: true, + obscureBackground: false, + hideNavigationBar: false, + autoCapitalize: 'sentences', + placeholder: 'Some text', + onChangeText: (e: NativeSyntheticEvent<{text: string}>) => + setSearch(e.nativeEvent.text), + onCancelButtonPress: () => console.warn('Cancel button pressed'), + onSearchButtonPress: () => console.warn('Search button pressed'), + onFocus: () => console.warn('onFocus event'), + onBlur: () => console.warn('onBlur event'), }; const items = [ @@ -77,7 +76,8 @@ function First({navigation}: NativeStackScreenProps) { return ( + keyboardDismissMode="on-drag" + collapsable={false}>