Open guilhermebruzzi opened 7 years ago
Wow, moving to WKWebview is a big jump. Which I wanted.
Are you using it in your own app and tested? Does it maintain same API as before, more or less?
@fungilation Are you using it in your own app and tested? <- Yes Does it maintain same API as before, more or less? <- Yes, only scalesPageToFit is not supported by wkwebview (all other props we used worked well)
I commented inline in code:
Any reason why this isn't changed to
#import <React/UIView+React.h>
?Same in
ios/RCTWebViewBridge.m
@fungilation No reason, sent a fix, TY! :)
Switched to your PR in my app, no bug so far that I can see. With noticeable improvement in WebViews' loading performance, much thanks for this!
@fungilation Nice! :D
The injectedJavaScript
property no longer works.
Do you have a good idea how to add that back in for WkWebView ?
I confirm that the WKWebView fork never worked. I mistakenly had the old version in my test app. On linking the new fork, app just crash to home screen on WebView's render.
I am using and need the injectedJavaScript
prop.
@fungilation it mostly works for me with a few tweaks (which were ok for my situation):
injectedJavaScript
and embedded into my document<script>
(function () {
function onWebViewBridgeReady() {
document.removeEventListener('WebViewBridge', onWebViewBridgeReady, false);
WebViewBridge.onMessage = function (message) {
// assume message has a color
document.body.style.backgroundColor = message;
}
}
WebViewBridge.send("webviewbridge-ready");
}
document.addEventListener('WebViewBridge', onWebViewBridgeReady, false)
}())
</script>
My document works with that and I can send/receive data over the bridge.
@fungilation @peterept I fixed now this injectedJavaScript
property and created a new example: examples/SampleRN42/ that you can use to test
@fungilation @peterept Anyway I never used injectedJavaScript
in my projects.
I always embedded in the document like @peterept said, because is way faster and should be your solution if you have control over the document
For me I need to inject JS, as I'm loading external websites. Thanks @guilhermebruzzi
Right. The code needs to use -[WKWebView evaluateJavaScript:completionHandler:]
to do the inject, but I'm not sure where react-native-webview-bridge needs to do the injection exactly.
@peterept I called the method on the same places that UIWebview used to call his inject method. Even If you call It earlier, the webview (on Android too) only allows the code to run after it has finished loading (If i'm not mistaken)
holy moley @guilhermebruzzi . I'm a fool... I cloned from your master branch on your fork (which has an older version of your code with WkWebView - missing the injection code). I'll switch to your branch feature/wkwebview
and report back!
Confirmed it works! That's awesome work @guilhermebruzzi.
I installed from the correct branch (although I see you've updated master now also):
$ npm install --save git://github.com/vtex/react-native-webview-bridge.git#feature/wkwebview
$ react-native run-ios
And now the injectedJavaScript={injectScript}
works and also the WebViewBridge
variable is set already (as in the sample code) and so no need to wait for it:
const injectScript = `
(function () {
if (WebViewBridge) {
document.body.style.backgroundColor = "red";
}
}());
`;
Thank you so much for this.
@peterept no problem! :) Yeah, you can install from master branch also.
@guilhermebruzzi how to use this pull request ? the master branch have problem!
@iOSHw What kind of problem?
To use the master branch you insert:
"react-native-webview-bridge": "vtex/react-native-webview-bridge",
on package.json dependencies
And than run npm install
and react-native link
@guilhermebruzzi Hi, bro. I really appreciate your hard working, but it seems not working under RN 0.44.2. Can you fix it?
Awesome! I couldn't get this library to work ("Cannot read property 'NavigationType' of undefined") until I installed this PR - THANKS! :D
@guilhermebruzzi @alinz is anybody working on fixing the conflicts and merging this branch into master?
@jenskuhrjorgensen I'm extremely busy that's why I'm constantly looking for good maintainer? Are you interested?
@alinz That's a shame - your library has been very useful to me! :) I'm afraid I don't have the time either.
No more deprecated webview on iOS and let people use webviewbridge API with RN 0.40+ I also included a new example SampleRN42 that shows that the main features still work.