Implement 'injectJavaScript' method
Summary: @public This diff introduces a method called `injectJavaScript(script)` on the React Native `<WKWebView/>` component. When called with a string, it evaluates that string as JavaScript within the web view. Reviewed By: shergin Differential Revision: D6367445 fbshipit-source-id: f68afeff42535dc991747f96a63f3c956faf13d3
This commit is contained in:
parent
90e85a4adc
commit
0022354525
|
@ -24,5 +24,6 @@
|
||||||
@property (nonatomic, assign) CGFloat decelerationRate;
|
@property (nonatomic, assign) CGFloat decelerationRate;
|
||||||
|
|
||||||
- (void)postMessage:(NSString *)message;
|
- (void)postMessage:(NSString *)message;
|
||||||
|
- (void)injectJavaScript:(NSString *)script;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -255,4 +255,9 @@ static NSString *const MessageHanderName = @"ReactNative";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)injectJavaScript:(NSString *)script
|
||||||
|
{
|
||||||
|
[self evaluateJS: script thenCall: nil];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -45,4 +45,16 @@ RCT_CUSTOM_VIEW_PROPERTY(decelerationRate, CGFloat, RCTWKWebView) {
|
||||||
view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
|
view.decelerationRate = json == nil ? UIScrollViewDecelerationRateNormal : [RCTConvert CGFloat: json];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RCT_EXPORT_METHOD(injectJavaScript:(nonnull NSNumber *)reactTag script:(NSString *)script)
|
||||||
|
{
|
||||||
|
[self.bridge.uiManager addUIBlock:^(__unused RCTUIManager *uiManager, NSDictionary<NSNumber *, RCTWKWebView *> *viewRegistry) {
|
||||||
|
RCTWKWebView *view = viewRegistry[reactTag];
|
||||||
|
if (![view isKindOfClass:[RCTWKWebView class]]) {
|
||||||
|
RCTLogError(@"Invalid view returned from registry, expecting RCTWebView, got: %@", view);
|
||||||
|
} else {
|
||||||
|
[view injectJavaScript:script];
|
||||||
|
}
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue