Skip to content

Commit be858f8

Browse files
authored
Fix [RNNEnterExitAnimation elementTransitions] crash (#7249)
Fix a crash caused by #7194 on `[RNNEnterExitAnimation elementTransitions]`. This is happening when trying to customize the modal animations. ``` EXCEPTION NSInvalidArgumentException MESSAGE -[RNNEnterExitAnimation elementTransitions]: unrecognized selector sent to instance 0x29d8f8720 ```
1 parent 1cd25e6 commit be858f8

File tree

8 files changed

+44
-99
lines changed

8 files changed

+44
-99
lines changed

lib/ios/RNNAnimationsOptions.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#import "RNNOptions.h"
22
#import "RNNScreenTransition.h"
33
#import "TransitionOptions.h"
4-
#import "ViewAnimationOptions.h"
54

65
@interface RNNAnimationsOptions : RNNOptions
76

lib/ios/RNNComponentPresenter.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
8484
withDefault:nil]
8585
tintColor:[options.topBar.searchBar.tintColor
8686
withDefault:nil]
87-
cancelText:[withDefault.topBar.searchBar.cancelText
88-
withDefault:nil]];
87+
cancelText:[withDefault.topBar.searchBar.cancelText
88+
withDefault:nil]];
8989
}
9090

9191
[_topBarTitlePresenter applyOptions:withDefault.topBar];
@@ -148,8 +148,8 @@ - (void)mergeOptions:(RNNNavigationOptions *)mergeOptions
148148
withDefault:nil]
149149
tintColor:[mergeOptions.topBar.searchBar.tintColor
150150
withDefault:nil]
151-
cancelText:[withDefault.topBar.searchBar.cancelText
152-
withDefault:nil]];
151+
cancelText:[withDefault.topBar.searchBar.cancelText
152+
withDefault:nil]];
153153
} else {
154154
[viewController setSearchBarVisible:NO];
155155
}

lib/ios/RNNEnterExitAnimation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
#import "RNNEnterExitAnimation.h"
2+
#import "SharedElementTransitionOptions.h"
13
#import "TransitionOptions.h"
24
#import <Foundation/Foundation.h>
35

46
@interface RNNEnterExitAnimation : RNNOptions
57

8+
@property(nonatomic, strong) NSArray<ElementTransitionOptions *> *elementTransitions;
9+
@property(nonatomic, strong) NSArray<SharedElementTransitionOptions *> *sharedElementTransitions;
610
@property(nonatomic, strong) TransitionOptions *enter;
711
@property(nonatomic, strong) TransitionOptions *exit;
812

lib/ios/RNNEnterExitAnimation.m

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "RNNEnterExitAnimation.h"
2+
#import "OptionsArrayParser.h"
23

34
@implementation RNNEnterExitAnimation
45

@@ -7,7 +8,12 @@ - (instancetype)initWithDict:(NSDictionary *)dict {
78

89
self.enter = [[TransitionOptions alloc] initWithDict:dict[@"enter"]];
910
self.exit = [[TransitionOptions alloc] initWithDict:dict[@"exit"]];
10-
11+
self.sharedElementTransitions = [OptionsArrayParser parse:dict
12+
key:@"sharedElementTransitions"
13+
ofClass:SharedElementTransitionOptions.class];
14+
self.elementTransitions = [OptionsArrayParser parse:dict
15+
key:@"elementTransitions"
16+
ofClass:ElementTransitionOptions.class];
1117
return self;
1218
}
1319

@@ -16,10 +22,15 @@ - (void)mergeOptions:(RNNEnterExitAnimation *)options {
1622
self.enter = options.enter;
1723
if (options.exit.hasValue)
1824
self.exit = options.exit;
25+
if (options.sharedElementTransitions)
26+
self.sharedElementTransitions = options.sharedElementTransitions;
27+
if (options.elementTransitions)
28+
self.elementTransitions = options.elementTransitions;
1929
}
2030

2131
- (BOOL)hasAnimation {
22-
return self.enter.hasAnimation || self.exit.hasAnimation;
32+
return self.enter.hasAnimation || self.exit.hasAnimation || self.elementTransitions ||
33+
self.sharedElementTransitions;
2334
}
2435

2536
- (NSTimeInterval)maxDuration {
@@ -29,6 +40,18 @@ - (NSTimeInterval)maxDuration {
2940
if (self.exit.maxDuration > maxDuration)
3041
maxDuration = self.exit.maxDuration;
3142

43+
for (ElementTransitionOptions *elementTransition in self.elementTransitions) {
44+
if (elementTransition.maxDuration > maxDuration) {
45+
maxDuration = elementTransition.maxDuration;
46+
}
47+
}
48+
49+
for (SharedElementTransitionOptions *sharedElementTransition in self.sharedElementTransitions) {
50+
if (sharedElementTransition.maxDuration > maxDuration) {
51+
maxDuration = sharedElementTransition.maxDuration;
52+
}
53+
}
54+
3255
return maxDuration;
3356
}
3457

lib/ios/RNNModalManager.m

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#import "ScreenAnimationController.h"
55
#import "ScreenReversedAnimationController.h"
66
#import "UIViewController+LayoutProtocol.h"
7-
#import "ViewAnimationOptions.h"
87

98
@interface RNNModalManager ()
109
@property(nonatomic, strong) ScreenAnimationController *showModalTransitionDelegate;
@@ -73,13 +72,13 @@ - (void)showModal:(UIViewController<RNNLayoutProtocol> *)viewController
7372
}
7473

7574
if (viewController.resolveOptionsWithDefault.animations.showModal.hasAnimation) {
76-
ViewAnimationOptions *viewAnimationOptions =
75+
RNNEnterExitAnimation *enterExitAnimationOptions =
7776
viewController.resolveOptionsWithDefault.animations.showModal;
7877
_showModalTransitionDelegate = [[ScreenAnimationController alloc]
79-
initWithContentTransition:viewAnimationOptions
80-
elementTransitions:viewAnimationOptions.elementTransitions
81-
sharedElementTransitions:viewAnimationOptions.sharedElementTransitions
82-
duration:viewAnimationOptions.maxDuration
78+
initWithContentTransition:enterExitAnimationOptions
79+
elementTransitions:enterExitAnimationOptions.elementTransitions
80+
sharedElementTransitions:enterExitAnimationOptions.sharedElementTransitions
81+
duration:enterExitAnimationOptions.maxDuration
8382
bridge:_bridge];
8483

8584
viewController.transitioningDelegate = _showModalTransitionDelegate;
@@ -108,7 +107,7 @@ - (void)dismissModal:(UIViewController *)viewController
108107
- (void)dismissAllModalsAnimated:(BOOL)animated completion:(void (^__nullable)(void))completion {
109108
UIViewController *root = [self rootViewController];
110109
if (root.presentedViewController) {
111-
ViewAnimationOptions *dismissModalOptions =
110+
RNNEnterExitAnimation *dismissModalOptions =
112111
root.presentedViewController.resolveOptionsWithDefault.animations.dismissModal;
113112
if (dismissModalOptions.hasAnimation) {
114113
_dismissModalTransitionDelegate = [[ScreenAnimationController alloc]
@@ -158,13 +157,13 @@ - (void)removePendingNextModalIfOnTop:(RNNTransitionCompletionBlock)completion
158157
UIViewController *topPresentedVC = [self topPresentedVC];
159158

160159
if (optionsWithDefault.animations.dismissModal.hasAnimation) {
161-
ViewAnimationOptions *viewAnimationOptions =
160+
RNNEnterExitAnimation *enterExitAnimationOptions =
162161
modalToDismiss.resolveOptionsWithDefault.animations.dismissModal;
163162
_dismissModalTransitionDelegate = [[ScreenReversedAnimationController alloc]
164-
initWithContentTransition:viewAnimationOptions
165-
elementTransitions:viewAnimationOptions.elementTransitions
166-
sharedElementTransitions:viewAnimationOptions.sharedElementTransitions
167-
duration:viewAnimationOptions.maxDuration
163+
initWithContentTransition:enterExitAnimationOptions
164+
elementTransitions:enterExitAnimationOptions.elementTransitions
165+
sharedElementTransitions:enterExitAnimationOptions.sharedElementTransitions
166+
duration:enterExitAnimationOptions.maxDuration
168167
bridge:_bridge];
169168

170169
[self topViewControllerParent:modalToDismiss].transitioningDelegate =

lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,6 @@
309309
50AD1CE123CB428400FF3134 /* TransitionOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50AD1CDF23CB428400FF3134 /* TransitionOptions.m */; };
310310
50AD288823CDB71C00FF3134 /* ElementHorizontalTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50AD288623CDB71C00FF3134 /* ElementHorizontalTransition.h */; };
311311
50AD288923CDB71C00FF3134 /* ElementHorizontalTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 50AD288723CDB71C00FF3134 /* ElementHorizontalTransition.m */; };
312-
50B92C26253DDC6D0056FC26 /* ViewAnimationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50B92C24253DDC6D0056FC26 /* ViewAnimationOptions.h */; };
313-
50B92C27253DDC6D0056FC26 /* ViewAnimationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B92C25253DDC6D0056FC26 /* ViewAnimationOptions.m */; };
314312
50BAFE4B2399405800798674 /* RNNExternalViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 50BAFE492399405800798674 /* RNNExternalViewController.h */; };
315313
50BAFE4C2399405800798674 /* RNNExternalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BAFE4A2399405800798674 /* RNNExternalViewController.m */; };
316314
50BCB27123F1650800D6C8E5 /* SharedElementTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50BCB26F23F1650800D6C8E5 /* SharedElementTransition.h */; };
@@ -843,8 +841,6 @@
843841
50AD1CDF23CB428400FF3134 /* TransitionOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TransitionOptions.m; sourceTree = "<group>"; };
844842
50AD288623CDB71C00FF3134 /* ElementHorizontalTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElementHorizontalTransition.h; sourceTree = "<group>"; };
845843
50AD288723CDB71C00FF3134 /* ElementHorizontalTransition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ElementHorizontalTransition.m; sourceTree = "<group>"; };
846-
50B92C24253DDC6D0056FC26 /* ViewAnimationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewAnimationOptions.h; sourceTree = "<group>"; };
847-
50B92C25253DDC6D0056FC26 /* ViewAnimationOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewAnimationOptions.m; sourceTree = "<group>"; };
848844
50BAFE492399405800798674 /* RNNExternalViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNExternalViewController.h; sourceTree = "<group>"; };
849845
50BAFE4A2399405800798674 /* RNNExternalViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNExternalViewController.m; sourceTree = "<group>"; };
850846
50BCB26F23F1650800D6C8E5 /* SharedElementTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedElementTransition.h; sourceTree = "<group>"; };
@@ -1400,8 +1396,6 @@
14001396
children = (
14011397
B8B2BB6324FFCC9500FC6575 /* CornerRadiusTransition.h */,
14021398
B8B2BB6424FFCC9500FC6575 /* CornerRadiusTransition.m */,
1403-
50B92C24253DDC6D0056FC26 /* ViewAnimationOptions.h */,
1404-
50B92C25253DDC6D0056FC26 /* ViewAnimationOptions.m */,
14051399
50F72E532607468C0096758A /* PathTransition.h */,
14061400
50F72E542607468C0096758A /* PathTransition.m */,
14071401
506BF65A2600AE4200A22755 /* CenterTransition.h */,
@@ -2032,7 +2026,6 @@
20322026
5038A3B1216DF41B009280BC /* UIViewController+RNNOptions.h in Headers */,
20332027
5049595A216F6B46006D2B81 /* NullDictionary.h in Headers */,
20342028
50BCB27123F1650800D6C8E5 /* SharedElementTransition.h in Headers */,
2035-
50B92C26253DDC6D0056FC26 /* ViewAnimationOptions.h in Headers */,
20362029
50BCB27D23F2A1EE00D6C8E5 /* FloatTransition.h in Headers */,
20372030
501224062173592D000F5F98 /* RNNBottomTabsPresenter.h in Headers */,
20382031
5017D9F2239D2FCB00B74047 /* BottomTabsOnSwitchToTabAttacher.h in Headers */,
@@ -2395,7 +2388,6 @@
23952388
5049593A216E5750006D2B81 /* Bool.m in Sources */,
23962389
50F5DFC61F407AA0001A00BC /* RNNStackController.m in Sources */,
23972390
21B85E5D1F44480200B314B5 /* RNNButtonsPresenter.m in Sources */,
2398-
50B92C27253DDC6D0056FC26 /* ViewAnimationOptions.m in Sources */,
23992391
E8E518371F83B94A000467AC /* RNNViewLocation.m in Sources */,
24002392
E3458D3E20BD9CE40023149B /* RNNPreviewOptions.m in Sources */,
24012393
5012242B217372B3000F5F98 /* ImageParser.m in Sources */,

lib/ios/ViewAnimationOptions.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

lib/ios/ViewAnimationOptions.m

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)