Skip to content

Commit 6181ea7

Browse files
authored
fix(ios): workaround for Alert not showing (#1097)
1 parent 6eb4356 commit 6181ea7

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

ios/ReactTestApp/React+Compatibility.m

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,45 @@ - (void)rta_displayLayer:(CALayer *)layer
9090
@end
9191

9292
#endif // !TARGET_OS_OSX && REACT_NATIVE_VERSION < 6302
93+
94+
// MARK: - [0.70.0] Alerts don't show when using UIScene
95+
// See https://github.com/facebook/react-native/pull/34562
96+
97+
#if !TARGET_OS_OSX && REACT_NATIVE_VERSION < 7100
98+
99+
#import <React/RCTAlertController.h>
100+
#import <React/RCTUtils.h>
101+
102+
@implementation RCTAlertController (ReactTestApp)
103+
104+
+ (void)initialize
105+
{
106+
if ([self class] != [RCTAlertController class]) {
107+
return;
108+
}
109+
110+
if (@available(iOS 13.0, *)) {
111+
static dispatch_once_t onceToken;
112+
dispatch_once(&onceToken, ^{
113+
RTASwizzleSelector([self class], @selector(hide), @selector(rta_hide));
114+
RTASwizzleSelector(
115+
[self class], @selector(show:completion:), @selector(rta_show:completion:));
116+
});
117+
}
118+
}
119+
120+
- (void)rta_hide
121+
{
122+
// noop
123+
}
124+
125+
- (void)rta_show:(BOOL)animated completion:(void (^)(void))completion
126+
{
127+
[[RCTKeyWindow() rootViewController] presentViewController:self
128+
animated:animated
129+
completion:completion];
130+
}
131+
132+
@end
133+
134+
#endif // !TARGET_OS_OSX && REACT_NATIVE_VERSION < 7100

0 commit comments

Comments
 (0)