Skip to content

Commit

Permalink
Fix build warnings on iOS (#6047)
Browse files Browse the repository at this point in the history
* Fix possible retain cycles in commands handler
* Fix compiler build warnings
  • Loading branch information
yogevbd authored Mar 17, 2020
1 parent 4413aa4 commit 3f8577d
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion lib/ios/BottomTabsPresenterCreator.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

@interface BottomTabsPresenterCreator : NSObject

+ (RNNBottomTabsPresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions;
+ (BottomTabsBasePresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions;

@end
2 changes: 1 addition & 1 deletion lib/ios/BottomTabsPresenterCreator.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

@implementation BottomTabsPresenterCreator

+ (RNNBottomTabsPresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
+ (BottomTabsBasePresenter *)createWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
if (@available(iOS 13.0, *)) {
return [[BottomTabsAppearancePresenter alloc] initWithDefaultOptions:defaultOptions];
} else {
Expand Down
2 changes: 0 additions & 2 deletions lib/ios/ElementFrameTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

@interface ElementFrameTransition : ElementBaseTransition

- (instancetype)initWithView:(UIView *)view from:(CGRect)from to:(CGRect)to startDelay:(NSTimeInterval)startDelay duration:(NSTimeInterval)duration interpolation:(Text *)interpolation;

@property (nonatomic) CGRect from;
@property (nonatomic) CGRect to;

Expand Down
26 changes: 13 additions & 13 deletions lib/ios/RNNBridgeModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,103 +21,103 @@ -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {

RCT_EXPORT_METHOD(setRoot:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler setRoot:layout commandId:commandId completion:^{
[self->_commandsHandler setRoot:layout commandId:commandId completion:^{
resolve(layout);
}];
});
}

RCT_EXPORT_METHOD(mergeOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler mergeOptions:componentId options:options completion:^{
[self->_commandsHandler mergeOptions:componentId options:options completion:^{
resolve(componentId);
}];
});
}

RCT_EXPORT_METHOD(setDefaultOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler setDefaultOptions:options completion:^{
[self->_commandsHandler setDefaultOptions:options completion:^{
resolve(nil);
}];
});
}

RCT_EXPORT_METHOD(push:(NSString*)commandId componentId:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
[self->_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
resolve(componentId);
} rejection:reject];
});
}

RCT_EXPORT_METHOD(pop:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler pop:componentId commandId:commandId mergeOptions:(NSDictionary*)options completion:^{
[self->_commandsHandler pop:componentId commandId:commandId mergeOptions:(NSDictionary*)options completion:^{
resolve(componentId);
} rejection:reject];
});
}

RCT_EXPORT_METHOD(setStackRoot:(NSString*)commandId componentId:(NSString*)componentId children:(NSArray*)children resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler setStackRoot:componentId commandId:commandId children:children completion:^{
[self->_commandsHandler setStackRoot:componentId commandId:commandId children:children completion:^{
resolve(componentId);
} rejection:reject];
});
}

RCT_EXPORT_METHOD(popTo:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler popTo:componentId commandId:commandId mergeOptions:options completion:^{
[self->_commandsHandler popTo:componentId commandId:commandId mergeOptions:options completion:^{
resolve(componentId);
} rejection:reject];
});
}

RCT_EXPORT_METHOD(popToRoot:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler popToRoot:componentId commandId:commandId mergeOptions:options completion:^{
[self->_commandsHandler popToRoot:componentId commandId:commandId mergeOptions:options completion:^{
resolve(componentId);
} rejection:reject];
});
}

RCT_EXPORT_METHOD(showModal:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler showModal:layout commandId:commandId completion:^(NSString *componentId) {
[self->_commandsHandler showModal:layout commandId:commandId completion:^(NSString *componentId) {
resolve(componentId);
}];
});
}

RCT_EXPORT_METHOD(dismissModal:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler dismissModal:componentId commandId:commandId mergeOptions:options completion:^{
[self->_commandsHandler dismissModal:componentId commandId:commandId mergeOptions:options completion:^{
resolve(componentId);
} rejection:reject];
});
}

RCT_EXPORT_METHOD(dismissAllModals:(NSString*)commandId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler dismissAllModals:options commandId:commandId completion:^{
[self->_commandsHandler dismissAllModals:options commandId:commandId completion:^{
resolve(nil);
}];
});
}

RCT_EXPORT_METHOD(showOverlay:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler showOverlay:layout commandId:commandId completion:^{
[self->_commandsHandler showOverlay:layout commandId:commandId completion:^{
resolve(layout[@"id"]);
}];
});
}

RCT_EXPORT_METHOD(dismissOverlay:(NSString*)commandId componentId:(NSString*)componentId resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
RCTExecuteOnMainQueue(^{
[_commandsHandler dismissOverlay:componentId commandId:commandId completion:^{
[self->_commandsHandler dismissOverlay:componentId commandId:commandId completion:^{
resolve(@(1));
} rejection:reject];
});
Expand Down
47 changes: 25 additions & 22 deletions lib/ios/RNNCommandsHandler.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ - (void)setRoot:(NSDictionary*)layout commandId:(NSString*)commandId completion:

UIViewController *vc = [_controllerFactory createLayout:layout[@"root"]];
vc.waitForRender = [vc.resolveOptionsWithDefault.animations.setRoot.waitForRender getWithDefaultValue:NO];

__weak UIViewController* weakVC = vc;
[vc setReactViewReadyCallback:^{
_mainWindow.rootViewController = vc;
[_eventEmitter sendOnNavigationCommandCompletion:setRoot commandId:commandId params:@{@"layout": layout}];
self->_mainWindow.rootViewController = weakVC;
[self->_eventEmitter sendOnNavigationCommandCompletion:setRoot commandId:commandId params:@{@"layout": layout}];
completion();
}];

Expand Down Expand Up @@ -160,8 +160,9 @@ - (void)push:(NSString*)componentId commandId:(NSString*)commandId layout:(NSDic
}
} else {
newVc.waitForRender = newVc.resolveOptionsWithDefault.animations.push.shouldWaitForRender;
__weak UIViewController* weakNewVC = newVc;
[newVc setReactViewReadyCallback:^{
[fromVC.stack push:newVc onTop:fromVC animated:[newVc.resolveOptionsWithDefault.animations.push.enable getWithDefaultValue:YES] completion:^{
[fromVC.stack push:weakNewVC onTop:fromVC animated:[weakNewVC.resolveOptionsWithDefault.animations.push.enable getWithDefaultValue:YES] completion:^{
[self->_eventEmitter sendOnNavigationCommandCompletion:push commandId:commandId params:@{@"componentId": componentId}];
completion();
} rejection:rejection];
Expand Down Expand Up @@ -202,17 +203,17 @@ - (void)pop:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(
RNNAssertMainQueue();

RNNComponentViewController *vc = (RNNComponentViewController*)[RNNLayoutManager findComponentForId:componentId];
if (vc) {
RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
[vc overrideOptions:options];
[vc.stack pop:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^{
[self->_eventEmitter sendOnNavigationCommandCompletion:pop commandId:commandId params:@{@"componentId": componentId}];
completion();
} rejection:rejection];
} else {
[RNNErrorHandler reject:rejection withErrorCode:1012 errorDescription:[NSString stringWithFormat:@"Popping component failed - componentId '%@' not found", componentId]];
}
if (vc) {
RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
[vc overrideOptions:options];

[vc.stack pop:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^{
[self->_eventEmitter sendOnNavigationCommandCompletion:pop commandId:commandId params:@{@"componentId": componentId}];
completion();
} rejection:rejection];
} else {
[RNNErrorHandler reject:rejection withErrorCode:1012 errorDescription:[NSString stringWithFormat:@"Popping component failed - componentId '%@' not found", componentId]];
}
}

- (void)popTo:(NSString*)componentId commandId:(NSString*)commandId mergeOptions:(NSDictionary *)mergeOptions completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
Expand All @@ -224,7 +225,7 @@ - (void)popTo:(NSString*)componentId commandId:(NSString*)commandId mergeOptions
[vc overrideOptions:options];

[vc.stack popTo:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] completion:^(NSArray *poppedViewControllers) {
[_eventEmitter sendOnNavigationCommandCompletion:popTo commandId:commandId params:@{@"componentId": componentId}];
[self->_eventEmitter sendOnNavigationCommandCompletion:popTo commandId:commandId params:@{@"componentId": componentId}];
completion();
} rejection:rejection];
}
Expand All @@ -239,7 +240,7 @@ - (void)popToRoot:(NSString*)componentId commandId:(NSString*)commandId mergeOpt

[CATransaction begin];
[CATransaction setCompletionBlock:^{
[_eventEmitter sendOnNavigationCommandCompletion:popToRoot commandId:commandId params:@{@"componentId": componentId}];
[self->_eventEmitter sendOnNavigationCommandCompletion:popToRoot commandId:commandId params:@{@"componentId": componentId}];
completion();
}];

Expand All @@ -257,11 +258,12 @@ - (void)showModal:(NSDictionary*)layout commandId:(NSString *)commandId completi
RNNAssertMainQueue();

UIViewController *newVc = [_controllerFactory createLayout:layout];
__weak UIViewController* weakNewVC = newVc;
newVc.waitForRender = [newVc.resolveOptionsWithDefault.animations.showModal.waitForRender getWithDefaultValue:NO];
[newVc setReactViewReadyCallback:^{
[_modalManager showModal:newVc animated:[newVc.resolveOptionsWithDefault.animations.showModal.enable getWithDefaultValue:YES] completion:^(NSString *componentId) {
[self->_modalManager showModal:weakNewVC animated:[weakNewVC.resolveOptionsWithDefault.animations.showModal.enable getWithDefaultValue:YES] completion:^(NSString *componentId) {
[self->_eventEmitter sendOnNavigationCommandCompletion:showModal commandId:commandId params:@{@"layout": layout}];
completion(newVc.layoutInfo.componentId);
completion(weakNewVC.layoutInfo.componentId);
}];
}];
[newVc render];
Expand Down Expand Up @@ -297,7 +299,7 @@ - (void)dismissAllModals:(NSDictionary *)mergeOptions commandId:(NSString*)comma

[CATransaction begin];
[CATransaction setCompletionBlock:^{
[_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals commandId:commandId params:@{}];
[self->_eventEmitter sendOnNavigationCommandCompletion:dismissAllModals commandId:commandId params:@{}];
completion();
}];
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
Expand All @@ -311,9 +313,10 @@ - (void)showOverlay:(NSDictionary *)layout commandId:(NSString*)commandId comple
RNNAssertMainQueue();

UIViewController* overlayVC = [_controllerFactory createLayout:layout];
__weak UIViewController* weakOverlayVC = overlayVC;
[overlayVC setReactViewReadyCallback:^{UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
overlayWindow.rootViewController = overlayVC;
if ([overlayVC.resolveOptionsWithDefault.overlay.handleKeyboardEvents getWithDefaultValue:NO]) {
overlayWindow.rootViewController = weakOverlayVC;
if ([weakOverlayVC.resolveOptionsWithDefault.overlay.handleKeyboardEvents getWithDefaultValue:NO]) {
[self->_overlayManager showOverlayWindowAsKeyWindow:overlayWindow];
} else {
[self->_overlayManager showOverlayWindow:overlayWindow];
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNControllerFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ - (UIViewController *)createStack:(RNNLayoutNode*)node {
- (UIViewController *)createBottomTabs:(RNNLayoutNode*)node {
RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] initWithNode:node];
RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:node.data[@"options"]];
RNNBottomTabsPresenter* presenter = [BottomTabsPresenterCreator createWithDefaultOptions:_defaultOptions];
BottomTabsBasePresenter* presenter = [BottomTabsPresenterCreator createWithDefaultOptions:_defaultOptions];
NSArray *childViewControllers = [self extractChildrenViewControllersFromNode:node];
BottomTabPresenter* bottomTabPresenter = [BottomTabPresenterCreator createWithDefaultOptions:_defaultOptions];
RNNDotIndicatorPresenter* dotIndicatorPresenter = [[RNNDotIndicatorPresenter alloc] initWithDefaultOptions:_defaultOptions];
Expand Down
18 changes: 9 additions & 9 deletions lib/ios/RNNModalManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
#import <React/RCTBridge.h>

typedef void (^RNNTransitionCompletionBlock)(void);
typedef void (^RNNTransitionWithComponentIdCompletionBlock)(NSString *componentId);
typedef void (^RNNTransitionRejectionBlock)(NSString *code, NSString *message, NSError *error);
typedef void (^RNNTransitionWithComponentIdCompletionBlock)(NSString * _Nonnull componentId);
typedef void (^RNNTransitionRejectionBlock)(NSString * _Nonnull code, NSString * _Nonnull message, NSError * _Nullable error);

@protocol RNNModalManagerDelegate <NSObject>

- (void)dismissedModal:(UIViewController *)viewController;
- (void)attemptedToDismissModal:(UIViewController *)viewController;
- (void)dismissedMultipleModals:(NSArray *)viewControllers;
- (void)dismissedModal:(UIViewController * _Nonnull)viewController;
- (void)attemptedToDismissModal:(UIViewController * _Nonnull)viewController;
- (void)dismissedMultipleModals:(NSArray * _Nonnull)viewControllers;

@end

@interface RNNModalManager : NSObject <UIAdaptivePresentationControllerDelegate>

- (instancetype)initWithBridge:(RCTBridge *)bridge;
- (instancetype _Nullable)initWithBridge:(RCTBridge * _Nonnull)bridge;

@property (nonatomic, weak) id<RNNModalManagerDelegate> delegate;
@property (nonatomic, weak) id<RNNModalManagerDelegate> _Nullable delegate;

- (void)showModal:(UIViewController *)viewController animated:(BOOL)animated completion:(RNNTransitionWithComponentIdCompletionBlock)completion;
- (void)dismissModal:(UIViewController *)viewController completion:(RNNTransitionCompletionBlock)completion;
- (void)showModal:(UIViewController * _Nonnull)viewController animated:(BOOL)animated completion:(RNNTransitionWithComponentIdCompletionBlock _Nonnull)completion;
- (void)dismissModal:(UIViewController * _Nonnull)viewController completion:(RNNTransitionCompletionBlock _Nonnull)completion;
- (void)dismissAllModalsAnimated:(BOOL)animated completion:(void (^ __nullable)(void))completion;
- (void)dismissAllModalsSynchronosly;

Expand Down
2 changes: 1 addition & 1 deletion lib/ios/RNNModalManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void)removePendingNextModalIfOnTop:(RNNTransitionCompletionBlock)completion {

if (modalToDismiss == topPresentedVC || [[topPresentedVC childViewControllers] containsObject:modalToDismiss]) {
[modalToDismiss dismissViewControllerAnimated:[optionsWithDefault.animations.dismissModal.enable getWithDefaultValue:YES] completion:^{
[_pendingModalIdsToDismiss removeObject:modalToDismiss];
[self->_pendingModalIdsToDismiss removeObject:modalToDismiss];
if (modalToDismiss.view) {
[self dismissedModal:modalToDismiss];
}
Expand Down
Loading

0 comments on commit 3f8577d

Please sign in to comment.