File tree Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Expand file tree Collapse file tree 4 files changed +26
-2
lines changed Original file line number Diff line number Diff line change 99@property (nonatomic , copy ) RCTDirectEventBlock _Nullable onLoad;
1010@property (nonatomic , copy ) RCTDirectEventBlock _Nullable onMessage;
1111
12+ - (nonnull instancetype )initWithFrame : (CGRect)frame NS_UNAVAILABLE;
13+ - (nonnull instancetype )initWithFrame : (CGRect)frame configuration : (nonnull WKWebViewConfiguration *)configuration NS_UNAVAILABLE;
14+ - (nullable instancetype )initWithCoder : (nonnull NSCoder *)coder NS_UNAVAILABLE;
15+
1216- (BOOL )scrollEnabled ;
1317- (void )setScrollEnabled : (BOOL )enabled ;
1418
Original file line number Diff line number Diff line change @@ -45,6 +45,17 @@ - (id)inputAccessoryView {
4545
4646@implementation RCTWebViewAlternative
4747
48+ - (instancetype )init {
49+ if ((self = [super init ])) { // -[UIView init] calls initWithFrame:, -[WKWebView initWithFrame:] calls initWithFrame:configuration:
50+ [self .configuration.userContentController addScriptMessageHandler: self name: @" jsMessageHandler" ];
51+ }
52+ return self;
53+ }
54+
55+ - (instancetype )initWithCoder : (NSCoder *)coder {
56+ @throw [NSException exceptionWithName: @" Unsupported method" reason: nil userInfo: nil ];
57+ }
58+
4859- (UIView *)contentView {
4960 UIView *contentView;
5061 [[self valueForKey: @" _contentView" ] getValue: &contentView];
@@ -167,4 +178,14 @@ - (void)userContentController:(WKUserContentController *)userContentController d
167178 });
168179}
169180
181+ #pragma mark - UIView
182+
183+ - (void )willMoveToSuperview : (UIView *)newSuperview {
184+ [super willMoveToSuperview: newSuperview];
185+
186+ if (newSuperview == nil ) {
187+ [self .configuration.userContentController removeScriptMessageHandlerForName: @" jsMessageHandler" ];
188+ }
189+ }
190+
170191@end
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ @implementation WebViewAlternativeManager
1515- (RCTWebViewAlternative *)view {
1616 RCTWebViewAlternative *view = [RCTWebViewAlternative new ];
1717 view.navigationDelegate = self;
18- [view.configuration.userContentController addScriptMessageHandler: view name: @" jsMessageHandler" ];
1918 return view;
2019}
2120
Original file line number Diff line number Diff line change 11{
22 "name" : " react-native-webview-alternative" ,
3- "version" : " 0.0.2 " ,
3+ "version" : " 0.0.3 " ,
44 "description" : " Alternative to react-native-webview" ,
55 "main" : " lib/commonjs/index.js" ,
66 "module" : " lib/module/index.js" ,
You can’t perform that action at this time.
0 commit comments