Skip to content

Commit 587a32b

Browse files
committed
Add workaround to dismiss SafariViewController without animation
1 parent fd382ea commit 587a32b

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ in case of vulnerabilities.
3030
- Activating Open Collective ([#80](https://github.com/proyecto26/react-native-inappbrowser/pull/80)) and Create **CONTRIBUTING.md** to see how to contribute.
3131
- Added `animated`, `modalPresentationStyle` and `modalTransitionStyle` properties for iOS options ([86f7238](https://github.com/proyecto26/react-native-inappbrowser/commit/86f7238d8eb856b28fae9981ca7bb42b12c43e18)).
3232
- Present the **SafariViewController** modally or as push instead using the `modalEnabled` property ([4a0d57c](https://github.com/proyecto26/react-native-inappbrowser/commit/4a0d57c73eccaaf45a212853c50aa41520b550c8)).
33+
- Add workaround to dismiss **SafariViewController** without animation.
3334

3435
### Removed
3536
- **com.facebook.infer.annotation** dependency is not required anymore to build for **Android**.

example/App.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ export default class App extends Component {
5353
preferredBarTintColor: '#453AA4',
5454
preferredControlTintColor: 'white',
5555
readerMode: false,
56-
animated: false,
56+
animated: true,
5757
modalPresentationStyle: 'overFullScreen',
5858
modalTransitionStyle: 'partialCurl',
59-
modalEnabled: false,
59+
modalEnabled: true,
6060
// Android Properties
6161
showTitle: true,
6262
toolbarColor: '#6200EE',

ios/RNInAppBrowser.m

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ - (dispatch_queue_t)methodQueue
138138
}
139139

140140
UIViewController *ctrl = RCTPresentedViewController();
141+
141142
if (modalEnabled) {
142143
safariVC.modalPresentationStyle = [self getPresentationStyle: modalPresentationStyle];
143144
if(animated) {
@@ -166,9 +167,10 @@ - (void)performSynchronouslyOnMainThread:(void (^)(void))block
166167
- (void)_close
167168
{
168169
__weak typeof(self) weakSelf = self;
170+
__weak typeof(BOOL) weakAnimated = animated;
169171
[self performSynchronouslyOnMainThread:^{
170172
UIViewController *ctrl = RCTPresentedViewController();
171-
[ctrl dismissViewControllerAnimated:animated completion:^{
173+
[ctrl dismissViewControllerAnimated:weakAnimated completion:^{
172174
__strong typeof(self) strongSelf = weakSelf;
173175
if (strongSelf && strongSelf.redirectResolve) {
174176
strongSelf.redirectResolve(@{
@@ -228,12 +230,13 @@ - (BOOL)initializeWebBrowserWithResolver:(RCTPromiseResolveBlock)resolve andReje
228230
*/
229231
- (void)safariViewControllerDidFinish:(SFSafariViewController *)controller
230232
{
231-
[controller dismissViewControllerAnimated:animated completion:nil];
233+
if (!animated) {
234+
[self dismissWithoutAnimation:controller];
235+
}
232236
_redirectResolve(@{
233237
@"type": @"cancel",
234238
});
235239
[self flowDidFinish];
236-
[self close];
237240
}
238241

239242
-(void)flowDidFinish
@@ -277,4 +280,23 @@ - (UIModalTransitionStyle)getTransitionStyle:(NSString *)styleKey {
277280
return modalTransitionStyle;
278281
}
279282

283+
- (void)dismissWithoutAnimation:(SFSafariViewController *)controller
284+
{
285+
CATransition* transition = [CATransition animation];
286+
transition.duration = 0.0;
287+
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
288+
transition.type = kCATransitionFade;
289+
transition.subtype = kCATransitionFromBottom;
290+
291+
controller.view.alpha = 0.05;
292+
controller.view.frame = CGRectMake(0.0, 0.0, 0.5, 0.5);
293+
294+
UIViewController *ctrl = RCTPresentedViewController();
295+
NSString* animationKey = @"dismissInAppBrowser";
296+
[ctrl.view.layer addAnimation:transition forKey:animationKey];
297+
[ctrl dismissViewControllerAnimated:false completion:^{
298+
[ctrl.view.layer removeAnimationForKey:animationKey];
299+
}];
300+
}
301+
280302
@end

0 commit comments

Comments
 (0)