Skip to content

Commit c862c7a

Browse files
committed
Remove close / onClose
1 parent 8ffa31b commit c862c7a

File tree

3 files changed

+4
-88
lines changed

3 files changed

+4
-88
lines changed

android/src/main/java/io/swan/rnbrowser/RNSwanBrowserModuleImpl.kt

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,35 @@
11
package io.swan.rnbrowser
22

33
import android.content.Intent
4-
import android.net.Uri
54

65
import androidx.annotation.ColorInt
76
import androidx.browser.customtabs.CustomTabColorSchemeParams
87
import androidx.browser.customtabs.CustomTabsIntent
98
import androidx.core.content.ContextCompat
109
import androidx.core.graphics.ColorUtils
10+
import androidx.core.net.toUri
1111

1212
import com.facebook.react.bridge.Promise
1313
import com.facebook.react.bridge.ReactApplicationContext
1414
import com.facebook.react.bridge.ReadableMap
15-
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter
1615

1716
import io.swan.rnbrowser.helpers.CustomTabActivityHelper
1817

1918
object RNSwanBrowserModuleImpl {
2019
const val NAME = "RNSwanBrowser"
21-
private var browserVisible = false
22-
23-
internal fun onHostResume(reactContext: ReactApplicationContext) {
24-
if (browserVisible && reactContext.hasActiveReactInstance()) {
25-
browserVisible = false
26-
27-
reactContext
28-
.getJSModule(RCTDeviceEventEmitter::class.java)
29-
.emit("swanBrowserDidClose", null)
30-
}
31-
}
3220

3321
internal fun open(
3422
reactContext: ReactApplicationContext,
3523
url: String,
3624
options: ReadableMap,
3725
promise: Promise
3826
) {
39-
if (browserVisible) {
40-
return promise.reject(
41-
"swan_browser_visible",
42-
"An instance of the swan browser is already visible"
43-
)
44-
}
45-
4627
val activity = reactContext.currentActivity
4728
?: return promise.reject(
4829
"no_current_activity",
4930
"Couldn't call open() when the app is in background"
5031
)
5132

52-
browserVisible = true
53-
5433
val intentBuilder = CustomTabsIntent.Builder().apply {
5534
setBookmarksButtonEnabled(false)
5635
setDownloadButtonEnabled(false)
@@ -95,7 +74,7 @@ object RNSwanBrowserModuleImpl {
9574
}
9675

9776
CustomTabActivityHelper.openCustomTab(
98-
activity, customTabsIntent, Uri.parse(url)
77+
activity, customTabsIntent, url.toUri()
9978
) { currentActivity, uri ->
10079
currentActivity.startActivity(Intent(Intent.ACTION_VIEW, uri))
10180
}
Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,19 @@
11
package io.swan.rnbrowser
22

3-
import com.facebook.react.bridge.LifecycleEventListener
43
import com.facebook.react.bridge.Promise
54
import com.facebook.react.bridge.ReactApplicationContext
65
import com.facebook.react.bridge.ReadableMap
76
import com.facebook.react.module.annotations.ReactModule
87

98
@ReactModule(name = RNSwanBrowserModuleImpl.NAME)
109
class RNSwanBrowserModule(reactContext: ReactApplicationContext) :
11-
NativeRNSwanBrowserSpec(reactContext),
12-
LifecycleEventListener {
13-
14-
init {
15-
reactApplicationContext.addLifecycleEventListener(this)
16-
}
17-
18-
override fun invalidate() {
19-
reactApplicationContext.removeLifecycleEventListener(this)
20-
}
10+
NativeRNSwanBrowserSpec(reactContext) {
2111

2212
override fun getName(): String {
2313
return RNSwanBrowserModuleImpl.NAME
2414
}
2515

26-
override fun onHostResume() {
27-
RNSwanBrowserModuleImpl.onHostResume(reactApplicationContext)
28-
}
29-
30-
override fun onHostPause() {}
31-
32-
override fun onHostDestroy() {}
33-
3416
override fun open(url: String, options: ReadableMap, promise: Promise) {
3517
RNSwanBrowserModuleImpl.open(reactApplicationContext, url, options, promise)
3618
}
37-
38-
override fun close() {
39-
// noop on Android since the modal is closed by deep-link
40-
}
41-
42-
override fun addListener(eventName: String) {
43-
// iOS only
44-
}
45-
46-
override fun removeListeners(count: Double) {
47-
// iOS only
48-
}
4919
}
Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.swan.rnbrowser
22

3-
import com.facebook.react.bridge.LifecycleEventListener
43
import com.facebook.react.bridge.Promise
54
import com.facebook.react.bridge.ReactApplicationContext
65
import com.facebook.react.bridge.ReactContextBaseJavaModule
@@ -10,46 +9,14 @@ import com.facebook.react.module.annotations.ReactModule
109

1110
@ReactModule(name = RNSwanBrowserModuleImpl.NAME)
1211
class RNSwanBrowserModule(reactContext: ReactApplicationContext) :
13-
ReactContextBaseJavaModule(reactContext),
14-
LifecycleEventListener {
15-
16-
init {
17-
reactApplicationContext.addLifecycleEventListener(this)
18-
}
19-
20-
override fun invalidate() {
21-
reactApplicationContext.removeLifecycleEventListener(this)
22-
}
12+
ReactContextBaseJavaModule(reactContext) {
2313

2414
override fun getName(): String {
2515
return RNSwanBrowserModuleImpl.NAME
2616
}
2717

28-
override fun onHostResume() {
29-
RNSwanBrowserModuleImpl.onHostResume(reactApplicationContext)
30-
}
31-
32-
override fun onHostPause() {}
33-
34-
override fun onHostDestroy() {}
35-
3618
@ReactMethod
3719
fun open(url: String, options: ReadableMap, promise: Promise) {
3820
RNSwanBrowserModuleImpl.open(reactApplicationContext, url, options, promise)
3921
}
40-
41-
@ReactMethod
42-
fun close() {
43-
// noop on Android since the modal is closed by deep-link
44-
}
45-
46-
@ReactMethod
47-
fun addListener(eventName: String) {
48-
// iOS only
49-
}
50-
51-
@ReactMethod
52-
fun removeListeners(count: Double) {
53-
// iOS only
54-
}
5522
}

0 commit comments

Comments
 (0)