From be9c217dfea4c8ac08d000a49f672f7f78977c81 Mon Sep 17 00:00:00 2001 From: Jamon Holmgren Date: Mon, 30 Jul 2018 20:21:48 -0700 Subject: [PATCH] Initial --- .gitignore | 49 + examples/WebViewExample.js | 492 ++ examples/WebbieSample/.babelrc | 3 + examples/WebbieSample/.buckconfig | 6 + examples/WebbieSample/.flowconfig | 67 + examples/WebbieSample/.gitattributes | 1 + examples/WebbieSample/.gitignore | 56 + examples/WebbieSample/.watchmanconfig | 1 + examples/WebbieSample/App.js | 46 + examples/WebbieSample/android/app/BUCK | 65 + .../WebbieSample/android/app/build.gradle | 155 + .../android/app/proguard-rules.pro | 17 + .../android/app/src/main/AndroidManifest.xml | 26 + .../java/com/webbiesample/MainActivity.java | 15 + .../com/webbiesample/MainApplication.java | 45 + .../src/main/res/mipmap-hdpi/ic_launcher.png | Bin 0 -> 3056 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 0 -> 5024 bytes .../src/main/res/mipmap-mdpi/ic_launcher.png | Bin 0 -> 2096 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 0 -> 2858 bytes .../src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 0 -> 4569 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 0 -> 7098 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 0 -> 6464 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 0 -> 10676 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 0 -> 9250 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 0 -> 15523 bytes .../app/src/main/res/values/strings.xml | 3 + .../app/src/main/res/values/styles.xml | 8 + examples/WebbieSample/android/build.gradle | 48 + .../WebbieSample/android/gradle.properties | 20 + .../android/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 52266 bytes .../gradle/wrapper/gradle-wrapper.properties | 5 + examples/WebbieSample/android/gradlew | 164 + examples/WebbieSample/android/gradlew.bat | 90 + examples/WebbieSample/android/keystores/BUCK | 8 + .../keystores/debug.keystore.properties | 4 + examples/WebbieSample/android/settings.gradle | 7 + examples/WebbieSample/app.json | 4 + examples/WebbieSample/index.js | 7 + .../ios/WebbieSample-tvOS/Info.plist | 54 + .../ios/WebbieSample-tvOSTests/Info.plist | 24 + .../WebbieSample.xcodeproj/project.pbxproj | 1468 +++++ .../xcschemes/WebbieSample-tvOS.xcscheme | 129 + .../xcschemes/WebbieSample.xcscheme | 129 + .../ios/WebbieSample/AppDelegate.h | 14 + .../ios/WebbieSample/AppDelegate.m | 35 + .../WebbieSample/Base.lproj/LaunchScreen.xib | 42 + .../AppIcon.appiconset/Contents.json | 38 + .../Images.xcassets/Contents.json | 6 + .../WebbieSample/ios/WebbieSample/Info.plist | 56 + examples/WebbieSample/ios/WebbieSample/main.m | 16 + .../ios/WebbieSampleTests/Info.plist | 24 + .../ios/WebbieSampleTests/WebbieSampleTests.m | 68 + examples/WebbieSample/package.json | 23 + examples/WebbieSample/yarn.lock | 5789 +++++++++++++++++ examples/XHRExampleCookies.js | 144 + package.json | 16 + src/android/build.gradle | 17 + src/android/src/main/AndroidManifest.xml | 2 + .../irwebview/ReactWebViewManager.java | 693 ++ .../infinitered/irwebview/WebViewConfig.java | 19 + .../events/TopLoadingErrorEvent.java | 47 + .../events/TopLoadingFinishEvent.java | 47 + .../events/TopLoadingStartEvent.java | 47 + .../irwebview/events/TopMessageEvent.java | 50 + src/ios/RCTWebView.h | 46 + src/ios/RCTWebView.m | 351 + src/ios/RCTWebViewManager.h | 12 + src/ios/RCTWebViewManager.m | 158 + src/js/WebView.android.js | 479 ++ src/js/WebView.integration.js | 75 + src/js/WebView.ios.js | 683 ++ src/js/WebViewShared.js | 26 + src/js/WebViewShared.test.js | 60 + yarn.lock | 7 + 74 files changed, 12306 insertions(+) create mode 100644 .gitignore create mode 100644 examples/WebViewExample.js create mode 100644 examples/WebbieSample/.babelrc create mode 100644 examples/WebbieSample/.buckconfig create mode 100644 examples/WebbieSample/.flowconfig create mode 100644 examples/WebbieSample/.gitattributes create mode 100644 examples/WebbieSample/.gitignore create mode 100644 examples/WebbieSample/.watchmanconfig create mode 100644 examples/WebbieSample/App.js create mode 100644 examples/WebbieSample/android/app/BUCK create mode 100644 examples/WebbieSample/android/app/build.gradle create mode 100644 examples/WebbieSample/android/app/proguard-rules.pro create mode 100644 examples/WebbieSample/android/app/src/main/AndroidManifest.xml create mode 100644 examples/WebbieSample/android/app/src/main/java/com/webbiesample/MainActivity.java create mode 100644 examples/WebbieSample/android/app/src/main/java/com/webbiesample/MainApplication.java create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-hdpi/ic_launcher.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-mdpi/ic_launcher.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png create mode 100644 examples/WebbieSample/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png create mode 100644 examples/WebbieSample/android/app/src/main/res/values/strings.xml create mode 100644 examples/WebbieSample/android/app/src/main/res/values/styles.xml create mode 100644 examples/WebbieSample/android/build.gradle create mode 100644 examples/WebbieSample/android/gradle.properties create mode 100644 examples/WebbieSample/android/gradle/wrapper/gradle-wrapper.jar create mode 100644 examples/WebbieSample/android/gradle/wrapper/gradle-wrapper.properties create mode 100755 examples/WebbieSample/android/gradlew create mode 100644 examples/WebbieSample/android/gradlew.bat create mode 100644 examples/WebbieSample/android/keystores/BUCK create mode 100644 examples/WebbieSample/android/keystores/debug.keystore.properties create mode 100644 examples/WebbieSample/android/settings.gradle create mode 100644 examples/WebbieSample/app.json create mode 100644 examples/WebbieSample/index.js create mode 100644 examples/WebbieSample/ios/WebbieSample-tvOS/Info.plist create mode 100644 examples/WebbieSample/ios/WebbieSample-tvOSTests/Info.plist create mode 100644 examples/WebbieSample/ios/WebbieSample.xcodeproj/project.pbxproj create mode 100644 examples/WebbieSample/ios/WebbieSample.xcodeproj/xcshareddata/xcschemes/WebbieSample-tvOS.xcscheme create mode 100644 examples/WebbieSample/ios/WebbieSample.xcodeproj/xcshareddata/xcschemes/WebbieSample.xcscheme create mode 100644 examples/WebbieSample/ios/WebbieSample/AppDelegate.h create mode 100644 examples/WebbieSample/ios/WebbieSample/AppDelegate.m create mode 100644 examples/WebbieSample/ios/WebbieSample/Base.lproj/LaunchScreen.xib create mode 100644 examples/WebbieSample/ios/WebbieSample/Images.xcassets/AppIcon.appiconset/Contents.json create mode 100644 examples/WebbieSample/ios/WebbieSample/Images.xcassets/Contents.json create mode 100644 examples/WebbieSample/ios/WebbieSample/Info.plist create mode 100644 examples/WebbieSample/ios/WebbieSample/main.m create mode 100644 examples/WebbieSample/ios/WebbieSampleTests/Info.plist create mode 100644 examples/WebbieSample/ios/WebbieSampleTests/WebbieSampleTests.m create mode 100644 examples/WebbieSample/package.json create mode 100644 examples/WebbieSample/yarn.lock create mode 100644 examples/XHRExampleCookies.js create mode 100644 package.json create mode 100644 src/android/build.gradle create mode 100644 src/android/src/main/AndroidManifest.xml create mode 100644 src/android/src/main/java/com/infinitered/irwebview/ReactWebViewManager.java create mode 100644 src/android/src/main/java/com/infinitered/irwebview/WebViewConfig.java create mode 100644 src/android/src/main/java/com/infinitered/irwebview/events/TopLoadingErrorEvent.java create mode 100644 src/android/src/main/java/com/infinitered/irwebview/events/TopLoadingFinishEvent.java create mode 100644 src/android/src/main/java/com/infinitered/irwebview/events/TopLoadingStartEvent.java create mode 100644 src/android/src/main/java/com/infinitered/irwebview/events/TopMessageEvent.java create mode 100644 src/ios/RCTWebView.h create mode 100644 src/ios/RCTWebView.m create mode 100644 src/ios/RCTWebViewManager.h create mode 100644 src/ios/RCTWebViewManager.m create mode 100644 src/js/WebView.android.js create mode 100644 src/js/WebView.integration.js create mode 100644 src/js/WebView.ios.js create mode 100644 src/js/WebViewShared.js create mode 100644 src/js/WebViewShared.test.js create mode 100644 yarn.lock 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 ? ( +