Files
react-native-webview/android/src/main/java/com/reactnativecommunity/webview/events/TopShouldStartLoadWithRequestEvent.kt
T
Caleb ClarkeandJamon Holmgren 6a9116f2d1 feat(events): Add isTopFrame to shouldStartLoadForRequest (#1537)
* Add isTopFrame to shouldStartLoadForRequest on iOS

onLoadingStart is not raised for inner frames, but onShouldStartLoadWithRequest still is. This keeps that behavior but adds isTopFrame to onShouldStartLoadWithRequest so that apps can perform their own filtering if desired.

* Update docs

Co-authored-by: Jamon Holmgren <jamonholmgren@gmail.com>
2020-08-15 11:21:38 +02:00

30 lines
935 B
Kotlin

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 shouldOverrideUrlLoading is called
*/
class TopShouldStartLoadWithRequestEvent(viewId: Int, private val mData: WritableMap) : Event<TopShouldStartLoadWithRequestEvent>(viewId) {
companion object {
const val EVENT_NAME = "topShouldStartLoadWithRequest"
}
init {
mData.putString("navigationType", "other")
// Android does not raise shouldOverrideUrlLoading for inner frames
mData.putBoolean("isTopFrame", true)
}
override fun getEventName(): String = EVENT_NAME
override fun canCoalesce(): Boolean = false
override fun getCoalescingKey(): Short = 0
override fun dispatch(rctEventEmitter: RCTEventEmitter) =
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, mData)
}