commit be9c217dfea4c8ac08d000a49f672f7f78977c81 Author: Jamon Holmgren Date: Mon Jul 30 20:21:48 2018 -0700 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7921ff5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,49 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace +Pods/ + +# Android/IJ +# +.idea +*.iml +.gradle +local.properties +lib/android/src/main/gen + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + +# Rubygem bundles +# +bundles/ + +# VS Code +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json diff --git a/examples/WebViewExample.js b/examples/WebViewExample.js new file mode 100644 index 0000000..92e0a4c --- /dev/null +++ b/examples/WebViewExample.js @@ -0,0 +1,492 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +var React = require('react'); +var ReactNative = require('react-native'); +var { + StyleSheet, + Text, + TextInput, + TouchableWithoutFeedback, + TouchableOpacity, + View, + WebView, +} = ReactNative; + +var HEADER = '#3b5998'; +var BGWASH = 'rgba(255,255,255,0.8)'; +var DISABLED_WASH = 'rgba(255,255,255,0.25)'; + +var TEXT_INPUT_REF = 'urlInput'; +var WEBVIEW_REF = 'webview'; +var DEFAULT_URL = 'https://m.facebook.com'; +const FILE_SYSTEM_ORIGIN_WHITE_LIST = ['file://*', 'http://*', 'https://*']; + +class WebViewExample extends React.Component<{}, $FlowFixMeState> { + state = { + url: DEFAULT_URL, + status: 'No Page Loaded', + backButtonEnabled: false, + forwardButtonEnabled: false, + loading: true, + scalesPageToFit: true, + }; + + inputText = ''; + + handleTextInputChange = event => { + var url = event.nativeEvent.text; + if (!/^[a-zA-Z-_]+:/.test(url)) { + url = 'http://' + url; + } + this.inputText = url; + }; + + render() { + this.inputText = this.state.url; + + return ( + + + + {'<'} + + + {'>'} + + + + + Go! + + + + + + {this.state.status} + + + ); + } + + goBack = () => { + this.refs[WEBVIEW_REF].goBack(); + }; + + goForward = () => { + this.refs[WEBVIEW_REF].goForward(); + }; + + reload = () => { + this.refs[WEBVIEW_REF].reload(); + }; + + onShouldStartLoadWithRequest = event => { + // Implement any custom loading logic here, don't forget to return! + return true; + }; + + onNavigationStateChange = navState => { + this.setState({ + backButtonEnabled: navState.canGoBack, + forwardButtonEnabled: navState.canGoForward, + url: navState.url, + status: navState.title, + loading: navState.loading, + scalesPageToFit: true, + }); + }; + + onSubmitEditing = event => { + this.pressGoButton(); + }; + + pressGoButton = () => { + var url = this.inputText.toLowerCase(); + if (url === this.state.url) { + this.reload(); + } else { + this.setState({ + url: url, + }); + } + // dismiss keyboard + this.refs[TEXT_INPUT_REF].blur(); + }; +} + +class Button extends React.Component<$FlowFixMeProps> { + _handlePress = () => { + if (this.props.enabled !== false && this.props.onPress) { + this.props.onPress(); + } + }; + + render() { + return ( + + + {this.props.text} + + + ); + } +} + +class ScaledWebView extends React.Component<{}, $FlowFixMeState> { + state = { + scalingEnabled: true, + }; + + render() { + return ( + + + + {this.state.scalingEnabled ? ( +