以下反应本机代码正在播放中。基本上,我想象中的代码将执行以下操作:
我收到的问题是:
origWebviewInstance.source = {uri: 'https://google.com'};
似乎我无法重定向到google.com
此处的示例代码:
import React, {Component} from 'react';
import { WebView } from "react-native-webview";
// singleton
import { MyWebview } from './src/MyWebview/MyWebview';
import Config from "react-native-config";
const loginUrl = Config.SITE_LOGIN_URL;
// header
let header = {
"Content-type": "application/json; charset=UTF-8"
};
// need to use double quote
let body = JSON.stringify({
"form_type": "customer_login",
"customer[email]": "user",
"customer[password]": "pass"
});
// header, body, post
const sourceObj = {
uri: loginUrl,
headers: header,
body: body,
method:'POST'
};
let webviewInstance = <WebView
source={sourceObj}
style={{ marginTop: 20 }}
onLoadProgress={e => console.log(e.nativeEvent.progress)}
/>;
// get empty instance
let myWebview = MyWebview.getInstance();
// inject the instance
myWebview.setWebview(webviewInstance);
// get webview instance
let origWebviewInstance = myWebview.getWebview();
// NOTE: not able to change url
origWebviewInstance.source = {uri: 'https://google.com'};
type Props = {};
export default class App extends Component<Props> {
render() {
return (
origWebviewInstance
);
}
}