Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix [RNNEnterExitAnimation elementTransitions] crash #7249

Merged
merged 1 commit into from
Sep 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion lib/ios/RNNAnimationsOptions.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#import "RNNOptions.h"
#import "RNNScreenTransition.h"
#import "TransitionOptions.h"
#import "ViewAnimationOptions.h"

@interface RNNAnimationsOptions : RNNOptions

Expand Down
8 changes: 4 additions & 4 deletions lib/ios/RNNComponentPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ - (void)applyOptions:(RNNNavigationOptions *)options {
withDefault:nil]
tintColor:[options.topBar.searchBar.tintColor
withDefault:nil]
cancelText:[withDefault.topBar.searchBar.cancelText
withDefault:nil]];
cancelText:[withDefault.topBar.searchBar.cancelText
withDefault:nil]];
}

[_topBarTitlePresenter applyOptions:withDefault.topBar];
Expand Down Expand Up @@ -148,8 +148,8 @@ - (void)mergeOptions:(RNNNavigationOptions *)mergeOptions
withDefault:nil]
tintColor:[mergeOptions.topBar.searchBar.tintColor
withDefault:nil]
cancelText:[withDefault.topBar.searchBar.cancelText
withDefault:nil]];
cancelText:[withDefault.topBar.searchBar.cancelText
withDefault:nil]];
} else {
[viewController setSearchBarVisible:NO];
}
Expand Down
4 changes: 4 additions & 0 deletions lib/ios/RNNEnterExitAnimation.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#import "RNNEnterExitAnimation.h"
#import "SharedElementTransitionOptions.h"
#import "TransitionOptions.h"
#import <Foundation/Foundation.h>

@interface RNNEnterExitAnimation : RNNOptions

@property(nonatomic, strong) NSArray<ElementTransitionOptions *> *elementTransitions;
@property(nonatomic, strong) NSArray<SharedElementTransitionOptions *> *sharedElementTransitions;
@property(nonatomic, strong) TransitionOptions *enter;
@property(nonatomic, strong) TransitionOptions *exit;

Expand Down
27 changes: 25 additions & 2 deletions lib/ios/RNNEnterExitAnimation.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "RNNEnterExitAnimation.h"
#import "OptionsArrayParser.h"

@implementation RNNEnterExitAnimation

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

self.enter = [[TransitionOptions alloc] initWithDict:dict[@"enter"]];
self.exit = [[TransitionOptions alloc] initWithDict:dict[@"exit"]];

self.sharedElementTransitions = [OptionsArrayParser parse:dict
key:@"sharedElementTransitions"
ofClass:SharedElementTransitionOptions.class];
self.elementTransitions = [OptionsArrayParser parse:dict
key:@"elementTransitions"
ofClass:ElementTransitionOptions.class];
return self;
}

Expand All @@ -16,10 +22,15 @@ - (void)mergeOptions:(RNNEnterExitAnimation *)options {
self.enter = options.enter;
if (options.exit.hasValue)
self.exit = options.exit;
if (options.sharedElementTransitions)
self.sharedElementTransitions = options.sharedElementTransitions;
if (options.elementTransitions)
self.elementTransitions = options.elementTransitions;
}

- (BOOL)hasAnimation {
return self.enter.hasAnimation || self.exit.hasAnimation;
return self.enter.hasAnimation || self.exit.hasAnimation || self.elementTransitions ||
self.sharedElementTransitions;
}

- (NSTimeInterval)maxDuration {
Expand All @@ -29,6 +40,18 @@ - (NSTimeInterval)maxDuration {
if (self.exit.maxDuration > maxDuration)
maxDuration = self.exit.maxDuration;

for (ElementTransitionOptions *elementTransition in self.elementTransitions) {
if (elementTransition.maxDuration > maxDuration) {
maxDuration = elementTransition.maxDuration;
}
}

for (SharedElementTransitionOptions *sharedElementTransition in self.sharedElementTransitions) {
if (sharedElementTransition.maxDuration > maxDuration) {
maxDuration = sharedElementTransition.maxDuration;
}
}

return maxDuration;
}

Expand Down
23 changes: 11 additions & 12 deletions lib/ios/RNNModalManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#import "ScreenAnimationController.h"
#import "ScreenReversedAnimationController.h"
#import "UIViewController+LayoutProtocol.h"
#import "ViewAnimationOptions.h"

@interface RNNModalManager ()
@property(nonatomic, strong) ScreenAnimationController *showModalTransitionDelegate;
Expand Down Expand Up @@ -73,13 +72,13 @@ - (void)showModal:(UIViewController<RNNLayoutProtocol> *)viewController
}

if (viewController.resolveOptionsWithDefault.animations.showModal.hasAnimation) {
ViewAnimationOptions *viewAnimationOptions =
RNNEnterExitAnimation *enterExitAnimationOptions =
viewController.resolveOptionsWithDefault.animations.showModal;
_showModalTransitionDelegate = [[ScreenAnimationController alloc]
initWithContentTransition:viewAnimationOptions
elementTransitions:viewAnimationOptions.elementTransitions
sharedElementTransitions:viewAnimationOptions.sharedElementTransitions
duration:viewAnimationOptions.maxDuration
initWithContentTransition:enterExitAnimationOptions
elementTransitions:enterExitAnimationOptions.elementTransitions
sharedElementTransitions:enterExitAnimationOptions.sharedElementTransitions
duration:enterExitAnimationOptions.maxDuration
bridge:_bridge];

viewController.transitioningDelegate = _showModalTransitionDelegate;
Expand Down Expand Up @@ -108,7 +107,7 @@ - (void)dismissModal:(UIViewController *)viewController
- (void)dismissAllModalsAnimated:(BOOL)animated completion:(void (^__nullable)(void))completion {
UIViewController *root = [self rootViewController];
if (root.presentedViewController) {
ViewAnimationOptions *dismissModalOptions =
RNNEnterExitAnimation *dismissModalOptions =
root.presentedViewController.resolveOptionsWithDefault.animations.dismissModal;
if (dismissModalOptions.hasAnimation) {
_dismissModalTransitionDelegate = [[ScreenAnimationController alloc]
Expand Down Expand Up @@ -158,13 +157,13 @@ - (void)removePendingNextModalIfOnTop:(RNNTransitionCompletionBlock)completion
UIViewController *topPresentedVC = [self topPresentedVC];

if (optionsWithDefault.animations.dismissModal.hasAnimation) {
ViewAnimationOptions *viewAnimationOptions =
RNNEnterExitAnimation *enterExitAnimationOptions =
modalToDismiss.resolveOptionsWithDefault.animations.dismissModal;
_dismissModalTransitionDelegate = [[ScreenReversedAnimationController alloc]
initWithContentTransition:viewAnimationOptions
elementTransitions:viewAnimationOptions.elementTransitions
sharedElementTransitions:viewAnimationOptions.sharedElementTransitions
duration:viewAnimationOptions.maxDuration
initWithContentTransition:enterExitAnimationOptions
elementTransitions:enterExitAnimationOptions.elementTransitions
sharedElementTransitions:enterExitAnimationOptions.sharedElementTransitions
duration:enterExitAnimationOptions.maxDuration
bridge:_bridge];

[self topViewControllerParent:modalToDismiss].transitioningDelegate =
Expand Down
8 changes: 0 additions & 8 deletions lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,6 @@
50AD1CE123CB428400FF3134 /* TransitionOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50AD1CDF23CB428400FF3134 /* TransitionOptions.m */; };
50AD288823CDB71C00FF3134 /* ElementHorizontalTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50AD288623CDB71C00FF3134 /* ElementHorizontalTransition.h */; };
50AD288923CDB71C00FF3134 /* ElementHorizontalTransition.m in Sources */ = {isa = PBXBuildFile; fileRef = 50AD288723CDB71C00FF3134 /* ElementHorizontalTransition.m */; };
50B92C26253DDC6D0056FC26 /* ViewAnimationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50B92C24253DDC6D0056FC26 /* ViewAnimationOptions.h */; };
50B92C27253DDC6D0056FC26 /* ViewAnimationOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50B92C25253DDC6D0056FC26 /* ViewAnimationOptions.m */; };
50BAFE4B2399405800798674 /* RNNExternalViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 50BAFE492399405800798674 /* RNNExternalViewController.h */; };
50BAFE4C2399405800798674 /* RNNExternalViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BAFE4A2399405800798674 /* RNNExternalViewController.m */; };
50BCB27123F1650800D6C8E5 /* SharedElementTransition.h in Headers */ = {isa = PBXBuildFile; fileRef = 50BCB26F23F1650800D6C8E5 /* SharedElementTransition.h */; };
Expand Down Expand Up @@ -843,8 +841,6 @@
50AD1CDF23CB428400FF3134 /* TransitionOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TransitionOptions.m; sourceTree = "<group>"; };
50AD288623CDB71C00FF3134 /* ElementHorizontalTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ElementHorizontalTransition.h; sourceTree = "<group>"; };
50AD288723CDB71C00FF3134 /* ElementHorizontalTransition.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ElementHorizontalTransition.m; sourceTree = "<group>"; };
50B92C24253DDC6D0056FC26 /* ViewAnimationOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewAnimationOptions.h; sourceTree = "<group>"; };
50B92C25253DDC6D0056FC26 /* ViewAnimationOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewAnimationOptions.m; sourceTree = "<group>"; };
50BAFE492399405800798674 /* RNNExternalViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNExternalViewController.h; sourceTree = "<group>"; };
50BAFE4A2399405800798674 /* RNNExternalViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNExternalViewController.m; sourceTree = "<group>"; };
50BCB26F23F1650800D6C8E5 /* SharedElementTransition.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SharedElementTransition.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1400,8 +1396,6 @@
children = (
B8B2BB6324FFCC9500FC6575 /* CornerRadiusTransition.h */,
B8B2BB6424FFCC9500FC6575 /* CornerRadiusTransition.m */,
50B92C24253DDC6D0056FC26 /* ViewAnimationOptions.h */,
50B92C25253DDC6D0056FC26 /* ViewAnimationOptions.m */,
50F72E532607468C0096758A /* PathTransition.h */,
50F72E542607468C0096758A /* PathTransition.m */,
506BF65A2600AE4200A22755 /* CenterTransition.h */,
Expand Down Expand Up @@ -2032,7 +2026,6 @@
5038A3B1216DF41B009280BC /* UIViewController+RNNOptions.h in Headers */,
5049595A216F6B46006D2B81 /* NullDictionary.h in Headers */,
50BCB27123F1650800D6C8E5 /* SharedElementTransition.h in Headers */,
50B92C26253DDC6D0056FC26 /* ViewAnimationOptions.h in Headers */,
50BCB27D23F2A1EE00D6C8E5 /* FloatTransition.h in Headers */,
501224062173592D000F5F98 /* RNNBottomTabsPresenter.h in Headers */,
5017D9F2239D2FCB00B74047 /* BottomTabsOnSwitchToTabAttacher.h in Headers */,
Expand Down Expand Up @@ -2395,7 +2388,6 @@
5049593A216E5750006D2B81 /* Bool.m in Sources */,
50F5DFC61F407AA0001A00BC /* RNNStackController.m in Sources */,
21B85E5D1F44480200B314B5 /* RNNButtonsPresenter.m in Sources */,
50B92C27253DDC6D0056FC26 /* ViewAnimationOptions.m in Sources */,
E8E518371F83B94A000467AC /* RNNViewLocation.m in Sources */,
E3458D3E20BD9CE40023149B /* RNNPreviewOptions.m in Sources */,
5012242B217372B3000F5F98 /* ImageParser.m in Sources */,
Expand Down
16 changes: 0 additions & 16 deletions lib/ios/ViewAnimationOptions.h

This file was deleted.

56 changes: 0 additions & 56 deletions lib/ios/ViewAnimationOptions.m

This file was deleted.