From a4f4c83729899b6f77812294e771deae05b48b9c Mon Sep 17 00:00:00 2001 From: Marc Rousavy Date: Tue, 28 Sep 2021 15:17:49 +0200 Subject: [PATCH] fix: Fix `RNScreens/RNSScreen.h` import if react-native-screens is not installed (#2377) ## Description When not having react-native-screens installed, react-native-reanimated does not build in alpha.3 (or current master). There is an import: ```objc #import ``` which does not work since RNScreens does not exist. This PR fixes this issue by conditionally importing RNScreens. ## Changes - Conditionally import RNScreens depending on whether it's installed or not - Conditionally use RNSScreen class depending on whether it's available or not --- ios/LayoutReanimation/REAUIManager.mm | 33 +++++++++++++++------------ 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/ios/LayoutReanimation/REAUIManager.mm b/ios/LayoutReanimation/REAUIManager.mm index 56bebf959c0..252f263062e 100644 --- a/ios/LayoutReanimation/REAUIManager.mm +++ b/ios/LayoutReanimation/REAUIManager.mm @@ -8,7 +8,10 @@ #import "RCTLayoutAnimationGroup.h" #import "REAIOSScheduler.h" #include "Scheduler.h" + +#if __has_include() #import +#endif @interface RCTUIManager(REA) - (void)_manageChildren:(NSNumber *)containerTag @@ -40,7 +43,7 @@ - (void)setBridge:(RCTBridge *)bridge { if(!_blockSetter) { _blockSetter = true; - + self.bridge = bridge; [super setValue:bridge forKey:@"_bridge"]; [self setValue:[bridge.uiManager valueForKey:@"_shadowViewRegistry"] forKey:@"_shadowViewRegistry"]; @@ -52,7 +55,7 @@ - (void)setBridge:(RCTBridge *)bridge [self setValue:[bridge.uiManager valueForKey:@"_rootViewTags"] forKey:@"_rootViewTags"]; [self setValue:[bridge.uiManager valueForKey:@"_observerCoordinator"] forKey:@"_observerCoordinator"]; [self setValue:[bridge.uiManager valueForKey:@"_componentDataByName"] forKey:@"_componentDataByName"]; - + _blockSetter = false; } } @@ -68,12 +71,12 @@ - (void)_manageChildren:(NSNumber *)containerTag BOOL isUIViewRegistry = ((id)registry == (id)[self valueForKey:@"_viewRegistry"]); id container; NSArray> *permanentlyRemovedChildren; - if(isUIViewRegistry) { - container = registry[containerTag]; + if(isUIViewRegistry) { + container = registry[containerTag]; for(id toRemoveChild in _toBeRemovedRegister[containerTag]) { [container removeReactSubview:toRemoveChild]; } - + permanentlyRemovedChildren = [super _childrenToRemoveFromContainer:container atIndices:removeAtIndices]; if(permanentlyRemovedChildren != nil) { for(id permanentlyRemovedChild in permanentlyRemovedChildren) { @@ -84,7 +87,7 @@ - (void)_manageChildren:(NSNumber *)containerTag } } } - + [super _manageChildren:containerTag moveFromIndices:moveFromIndices moveToIndices:moveToIndices @@ -92,7 +95,7 @@ - (void)_manageChildren:(NSNumber *)containerTag addAtIndices:addAtIndices removeAtIndices:removeAtIndices registry:registry]; - + if(isUIViewRegistry) { NSMutableDictionary> *viewRegistry = [self valueForKey:@"_viewRegistry"]; for(id toRemoveChild in _toBeRemovedRegister[containerTag]) { @@ -103,7 +106,7 @@ - (void)_manageChildren:(NSNumber *)containerTag [container insertReactSubview:toRemoveChild atIndex:lastIndex]; viewRegistry[toRemoveChild.reactTag] = toRemoveChild; } - + for (UIView *removedChild in permanentlyRemovedChildren) { [self callAnimationForTree: removedChild parentTag:containerTag]; } @@ -115,7 +118,7 @@ - (void) callAnimationForTree:(UIView*) view parentTag:(NSNumber*) parentTag REASnapshot* snapshot = [[REASnapshot alloc] init:view]; _parentMapper[view.reactTag] = parentTag; [_animationsManager onViewRemoval:view before:snapshot]; - + for(UIView* subView in view.reactSubviews) { [self callAnimationForTree:subView parentTag:view.reactTag]; } @@ -123,7 +126,7 @@ - (void) callAnimationForTree:(UIView*) view parentTag:(NSNumber*) parentTag // Overrided https://github.com/facebook/react-native/blob/v0.65.0/React/Modules/RCTUIManager.m#L530 - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView *)rootShadowView -{ +{ NSHashTable *affectedShadowViews = [NSHashTable weakObjectsHashTable]; [rootShadowView layoutWithAffectedShadowViews:affectedShadowViews]; @@ -232,7 +235,7 @@ - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView * if (view.isHidden != isHidden) { view.hidden = isHidden; } - + REASnapshot* snapshotBefore = [[REASnapshot alloc] init:view]; if (creatingLayoutAnimation) { // Animate view creation @@ -278,7 +281,7 @@ - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView * [view reactSetFrame:frame]; completion(YES); } - + if(isNew) { REASnapshot* snapshot = [[REASnapshot alloc] init:view]; [_animationsManager onViewCreate:view after:snapshot]; @@ -287,7 +290,7 @@ - (RCTViewManagerUIBlock)uiBlockWithLayoutUpdateForRootView:(RCTRootShadowView * REASnapshot* snapshotAfter = [[REASnapshot alloc] init:view]; [_animationsManager onViewUpdate:view before:snapshotBefore after:snapshotAfter]; } - + } [_animationsManager removeLeftovers]; @@ -319,7 +322,7 @@ - (void)unregisterView:(id) view if(tag == nil) { return; } - + [_toBeRemovedRegister[tag] removeObject:view]; if(_toBeRemovedRegister[tag].count == 0) { [_toBeRemovedRegister removeObjectForKey:tag]; @@ -328,9 +331,11 @@ - (void)unregisterView:(id) view [view.reactSuperview removeReactSubview:view]; id parentView = viewRegistry[tag]; [parentView removeReactSubview:view]; +#if __has_include() if ([view isKindOfClass:[RNSScreenView class]]) { [parentView didUpdateReactSubviews]; } +#endif [viewRegistry removeObjectForKey:view.reactTag]; }