diff --git a/.gitignore b/.gitignore index 330ae6a..a80b145 100644 --- a/.gitignore +++ b/.gitignore @@ -48,3 +48,7 @@ bundles/ !.vscode/tasks.json !.vscode/launch.json !.vscode/extensions.json + +android/gradle +android/gradlew +android/gradlew.bat \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index d814e4f..5342077 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,22 +1,91 @@ -apply plugin: 'com.android.library' +buildscript { + ext.kotlin_version = '1.2.71' + repositories { + google() + jcenter() + maven { + url 'https://maven.fabric.io/public' + } + } + dependencies { + classpath 'com.android.tools.build:gradle:3.2.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + } +} -def DEFAULT_COMPILE_SDK_VERSION = 27 -def DEFAULT_BUILD_TOOLS_VERSION = "27.0.3" -def DEFAULT_MIN_SDK_VERSION = 16 -def DEFAULT_TARGET_SDK_VERSION = 26 +apply plugin: 'com.android.library' +apply plugin: 'kotlin-android' + + +def DEFAULT_COMPILE_SDK_VERSION = 27 +def DEFAULT_BUILD_TOOLS_VERSION = "28.0.3" +def DEFAULT_TARGET_SDK_VERSION = 27 android { - compileSdkVersion rootProject.findProperty('compileSdkVersion') ?: DEFAULT_COMPILE_SDK_VERSION - buildToolsVersion rootProject.findProperty('buildToolsVersion') ?: DEFAULT_BUILD_TOOLS_VERSION - + compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION + buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION defaultConfig { - minSdkVersion rootProject.findProperty('minSdkVersion') ?: DEFAULT_MIN_SDK_VERSION - targetSdkVersion rootProject.findProperty('targetSdkVersion') ?: DEFAULT_TARGET_SDK_VERSION + minSdkVersion 16 + targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION versionCode 1 versionName "1.0" } + buildTypes { + release { + minifyEnabled false + } + } + productFlavors { + } + lintOptions { + disable 'GradleCompatible' + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } +} + +repositories { + mavenCentral() + maven { + url 'https://maven.google.com/' + name 'Google' + } + + // Stolen from react-native-firebase, thanks dudes! + def found = false + def parentDir = rootProject.projectDir + def reactNativeAndroidName = 'React Native (Node Modules)' + + 1.upto(4, { + if (found) return true + parentDir = parentDir.parentFile + def reactNativeAndroid = new File( + parentDir, + 'node_modules/react-native/android' + ) + + if (reactNativeAndroid.exists()) { + maven { + url reactNativeAndroid.toString() + name reactNativeAndroidName + } + + println "${project.name}: using React Native sources from ${reactNativeAndroid.toString()}" + found = true + } + }) + + if (!found) { + throw new GradleException( + "${project.name}: unable to locate React Native Android sources, " + + "ensure you have you installed React Native as a dependency and try again." + ) + } } dependencies { implementation 'com.facebook.react:react-native:+' + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" } diff --git a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java index 891c849..3a7ae87 100644 --- a/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +++ b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java @@ -56,12 +56,6 @@ import com.reactnativecommunity.webview.events.TopLoadingFinishEvent; import com.reactnativecommunity.webview.events.TopLoadingStartEvent; import com.reactnativecommunity.webview.events.TopMessageEvent; import com.reactnativecommunity.webview.events.TopLoadingProgressEvent; -import java.io.UnsupportedEncodingException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Locale; -import java.util.Map; -import javax.annotation.Nullable; import org.json.JSONException; import org.json.JSONObject; @@ -510,6 +504,7 @@ public class RNCWebViewManager extends SimpleViewManager { } } + @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) @ReactProp(name = "mediaPlaybackRequiresUserAction") public void setMediaPlaybackRequiresUserAction(WebView view, boolean requires) { view.getSettings().setMediaPlaybackRequiresUserGesture(requires); diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.java b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.java deleted file mode 100644 index 037e4c3..0000000 --- a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.reactnativecommunity.webview.events; - -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -/** - * Event emitted when there is an error in loading. - */ -public class TopLoadingErrorEvent extends Event { - - public static final String EVENT_NAME = "topLoadingError"; - private WritableMap mEventData; - - public TopLoadingErrorEvent(int viewId, WritableMap eventData) { - super(viewId); - mEventData = eventData; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - return false; - } - - @Override - public short getCoalescingKey() { - // All events for a given view can be coalesced. - return 0; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mEventData); - } -} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.kt b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.kt new file mode 100644 index 0000000..554e249 --- /dev/null +++ b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingErrorEvent.kt @@ -0,0 +1,25 @@ +package com.reactnativecommunity.webview.events + +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.events.Event +import com.facebook.react.uimanager.events.RCTEventEmitter + +/** + * Event emitted when there is an error in loading. + */ +class TopLoadingErrorEvent(viewId: Int, private val mEventData: WritableMap) : + Event(viewId) { + companion object { + const val EVENT_NAME = "topLoadingError" + } + + override fun getEventName(): String = EVENT_NAME + + override fun canCoalesce(): Boolean = false + + override fun getCoalescingKey(): Short = 0 + + override fun dispatch(rctEventEmitter: RCTEventEmitter) = + rctEventEmitter.receiveEvent(viewTag, eventName, mEventData) + +} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.java b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.java deleted file mode 100644 index 85fc2dd..0000000 --- a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.reactnativecommunity.webview.events; - -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -/** - * Event emitted when loading is completed. - */ -public class TopLoadingFinishEvent extends Event { - - public static final String EVENT_NAME = "topLoadingFinish"; - private WritableMap mEventData; - - public TopLoadingFinishEvent(int viewId, WritableMap eventData) { - super(viewId); - mEventData = eventData; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - return false; - } - - @Override - public short getCoalescingKey() { - // All events for a given view can be coalesced. - return 0; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mEventData); - } -} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.kt b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.kt new file mode 100644 index 0000000..90bb5c5 --- /dev/null +++ b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingFinishEvent.kt @@ -0,0 +1,24 @@ +package com.reactnativecommunity.webview.events + +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.events.Event +import com.facebook.react.uimanager.events.RCTEventEmitter + +/** + * Event emitted when loading is completed. + */ +class TopLoadingFinishEvent(viewId: Int, private val mEventData: WritableMap) : + Event(viewId) { + companion object { + const val EVENT_NAME = "topLoadingFinish" + } + + override fun getEventName(): String = EVENT_NAME + + override fun canCoalesce(): Boolean = false + + override fun getCoalescingKey(): Short = 0 + + override fun dispatch(rctEventEmitter: RCTEventEmitter) = + rctEventEmitter.receiveEvent(viewTag, eventName, mEventData) +} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.java b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.java deleted file mode 100644 index 41d7620..0000000 --- a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.reactnativecommunity.webview.events; - -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -public class TopLoadingProgressEvent extends Event { - public static final String EVENT_NAME = "topLoadingProgress"; - private WritableMap mEventData; - - public TopLoadingProgressEvent(int viewId, WritableMap eventData) { - super(viewId); - mEventData = eventData; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - return false; - } - - @Override - public short getCoalescingKey() { - // All events for a given view can be coalesced. - return 0; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mEventData); - } -} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.kt b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.kt new file mode 100644 index 0000000..9916cc3 --- /dev/null +++ b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingProgressEvent.kt @@ -0,0 +1,24 @@ +package com.reactnativecommunity.webview.events + +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.events.Event +import com.facebook.react.uimanager.events.RCTEventEmitter + +/** + * Event emitted when there is a loading progress event. + */ +class TopLoadingProgressEvent(viewId: Int, private val mEventData: WritableMap) : + Event(viewId) { + companion object { + const val EVENT_NAME = "topLoadingProgress" + } + + override fun getEventName(): String = EVENT_NAME + + override fun canCoalesce(): Boolean = false + + override fun getCoalescingKey(): Short = 0 + + override fun dispatch(rctEventEmitter: RCTEventEmitter) = + rctEventEmitter.receiveEvent(viewTag, eventName, mEventData) +} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.java b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.java deleted file mode 100644 index 214a5fb..0000000 --- a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.reactnativecommunity.webview.events; - -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -/** - * Event emitted when loading has started - */ -public class TopLoadingStartEvent extends Event { - - public static final String EVENT_NAME = "topLoadingStart"; - private WritableMap mEventData; - - public TopLoadingStartEvent(int viewId, WritableMap eventData) { - super(viewId); - mEventData = eventData; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - return false; - } - - @Override - public short getCoalescingKey() { - // All events for a given view can be coalesced. - return 0; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - rctEventEmitter.receiveEvent(getViewTag(), getEventName(), mEventData); - } -} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.kt b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.kt new file mode 100644 index 0000000..fdc2159 --- /dev/null +++ b/android/src/main/java/com/reactnativecommunity/webview/events/TopLoadingStartEvent.kt @@ -0,0 +1,25 @@ +package com.reactnativecommunity.webview.events + +import com.facebook.react.bridge.WritableMap +import com.facebook.react.uimanager.events.Event +import com.facebook.react.uimanager.events.RCTEventEmitter + +/** + * Event emitted when loading has started + */ +class TopLoadingStartEvent(viewId: Int, private val mEventData: WritableMap) : + Event(viewId) { + companion object { + const val EVENT_NAME = "topLoadingStart" + } + + override fun getEventName(): String = EVENT_NAME + + override fun canCoalesce(): Boolean = false + + override fun getCoalescingKey(): Short = 0 + + override fun dispatch(rctEventEmitter: RCTEventEmitter) = + rctEventEmitter.receiveEvent(viewTag, eventName, mEventData) + +} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.java b/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.java deleted file mode 100644 index 1e91668..0000000 --- a/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.reactnativecommunity.webview.events; - -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.bridge.Arguments; -import com.facebook.react.uimanager.events.Event; -import com.facebook.react.uimanager.events.RCTEventEmitter; - -/** - * Event emitted when there is an error in loading. - */ -public class TopMessageEvent extends Event { - - public static final String EVENT_NAME = "topMessage"; - private final String mData; - - public TopMessageEvent(int viewId, String data) { - super(viewId); - mData = data; - } - - @Override - public String getEventName() { - return EVENT_NAME; - } - - @Override - public boolean canCoalesce() { - return false; - } - - @Override - public short getCoalescingKey() { - // All events for a given view can be coalesced. - return 0; - } - - @Override - public void dispatch(RCTEventEmitter rctEventEmitter) { - WritableMap data = Arguments.createMap(); - data.putString("data", mData); - rctEventEmitter.receiveEvent(getViewTag(), EVENT_NAME, data); - } -} diff --git a/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.kt b/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.kt new file mode 100644 index 0000000..b9d9152 --- /dev/null +++ b/android/src/main/java/com/reactnativecommunity/webview/events/TopMessageEvent.kt @@ -0,0 +1,26 @@ +package com.reactnativecommunity.webview.events + +import com.facebook.react.bridge.Arguments +import com.facebook.react.uimanager.events.Event +import com.facebook.react.uimanager.events.RCTEventEmitter + +/** + * Event emitted when there is an error in loading. + */ +class TopMessageEvent(viewId: Int, private val mData: String) : Event(viewId) { + companion object { + const val EVENT_NAME = "topMessage" + } + + override fun getEventName(): String = EVENT_NAME + + override fun canCoalesce(): Boolean = false + + override fun getCoalescingKey(): Short = 0 + + override fun dispatch(rctEventEmitter: RCTEventEmitter) { + val data = Arguments.createMap() + data.putString("data", mData) + rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, data) + } +} diff --git a/docs/Reference.md b/docs/Reference.md index 88379a8..181fffe 100644 --- a/docs/Reference.md +++ b/docs/Reference.md @@ -110,7 +110,7 @@ Set this to provide JavaScript that will be injected into the web page when the ### `mediaPlaybackRequiresUserAction` -Boolean that determines whether HTML5 audio and video requires the user to tap them before they start playing. The default value is `true`. +Boolean that determines whether HTML5 audio and video requires the user to tap them before they start playing. The default value is `true`. (Android API minimum version 17) | Type | Required | | ---- | -------- | @@ -497,6 +497,8 @@ If true, this will be able horizontal swipe gestures when using the WKWebView. T | ------- | -------- | -------- | | boolean | No | iOS | +--- + ### `allowFileAccess` If true, this will allow access to the file system via `file://` URI's. The default value is `false`. @@ -505,6 +507,8 @@ If true, this will allow access to the file system via `file://` URI's. The defa | ------- | -------- | -------- | | boolean | No | Android | +--- + ### `saveFormDataDisabled` Sets whether the WebView should disable saving form data. The default value is `false`. This function does not have any effect from Android API level 26 onwards as there is an Autofill feature which stores form data. @@ -556,7 +560,7 @@ Stop loading the current page. ### `injectJavaScript(str)` ```javascript -injectJavaScript("... javascript string ..."); +injectJavaScript('... javascript string ...'); ``` Executes the JavaScript string.