-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
4,412 additions
and
4,182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 0 additions & 84 deletions
84
android/src/main/java/io/swan/rnbrowser/RNSwanBrowserModuleImpl.java
This file was deleted.
Oops, something went wrong.
105 changes: 105 additions & 0 deletions
105
android/src/main/java/io/swan/rnbrowser/RNSwanBrowserModuleImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package io.swan.rnbrowser | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
|
||
import androidx.annotation.ColorInt | ||
import androidx.browser.customtabs.CustomTabColorSchemeParams | ||
import androidx.browser.customtabs.CustomTabsIntent | ||
import androidx.core.content.ContextCompat | ||
import androidx.core.graphics.ColorUtils | ||
|
||
import com.facebook.react.bridge.Promise | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.bridge.ReadableMap | ||
import com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter | ||
|
||
import io.swan.rnbrowser.helpers.CustomTabActivityHelper | ||
|
||
object RNSwanBrowserModuleImpl { | ||
const val NAME = "RNSwanBrowser" | ||
private var browserVisible = false | ||
|
||
internal fun onHostResume(reactContext: ReactApplicationContext) { | ||
if (browserVisible && reactContext.hasActiveReactInstance()) { | ||
browserVisible = false | ||
|
||
reactContext | ||
.getJSModule(RCTDeviceEventEmitter::class.java) | ||
.emit("swanBrowserDidClose", null) | ||
} | ||
} | ||
|
||
internal fun open( | ||
reactContext: ReactApplicationContext, | ||
url: String, | ||
options: ReadableMap, | ||
promise: Promise | ||
) { | ||
if (browserVisible) { | ||
return promise.reject( | ||
"swan_browser_visible", | ||
"An instance of the swan browser is already visible" | ||
) | ||
} | ||
|
||
val activity = reactContext.currentActivity | ||
?: return promise.reject( | ||
"no_current_activity", | ||
"Couldn't call open() when the app is in background" | ||
) | ||
|
||
browserVisible = true | ||
|
||
val intentBuilder = CustomTabsIntent.Builder().apply { | ||
setBookmarksButtonEnabled(false) | ||
setDownloadButtonEnabled(false) | ||
setInstantAppsEnabled(false) | ||
setSendToExternalDefaultHandlerEnabled(false) | ||
setShowTitle(false) | ||
|
||
if (options.getString("animationType") == "fade") { | ||
setStartAnimations(activity, com.facebook.react.R.anim.catalyst_fade_in, R.anim.inert) | ||
setExitAnimations(activity, R.anim.inert, com.facebook.react.R.anim.catalyst_fade_out) | ||
} else { | ||
setStartAnimations(activity, com.facebook.react.R.anim.catalyst_slide_up, R.anim.inert) | ||
setExitAnimations(activity, R.anim.inert, com.facebook.react.R.anim.catalyst_slide_down) | ||
} | ||
} | ||
|
||
@ColorInt val blackColor = ContextCompat.getColor(activity ,android.R.color.black) | ||
|
||
val paramsBuilder = CustomTabColorSchemeParams.Builder().apply { | ||
setNavigationBarColor(blackColor) | ||
|
||
if (options.hasKey("barTintColor")) { | ||
@ColorInt val barTintColor = options.getInt("barTintColor") | ||
|
||
setToolbarColor(barTintColor) | ||
setSecondaryToolbarColor(barTintColor) | ||
|
||
intentBuilder.setColorScheme( | ||
when (ColorUtils.calculateLuminance(barTintColor) > 0.5) { | ||
true -> CustomTabsIntent.COLOR_SCHEME_LIGHT | ||
false -> CustomTabsIntent.COLOR_SCHEME_DARK | ||
} | ||
) | ||
} | ||
} | ||
|
||
intentBuilder.setDefaultColorSchemeParams(paramsBuilder.build()) | ||
|
||
val customTabsIntent = intentBuilder.build().apply { | ||
intent.addFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) | ||
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP) | ||
} | ||
|
||
CustomTabActivityHelper.openCustomTab( | ||
activity, customTabsIntent, Uri.parse(url) | ||
) { currentActivity, uri -> | ||
currentActivity.startActivity(Intent(Intent.ACTION_VIEW, uri)) | ||
} | ||
|
||
promise.resolve(null) | ||
} | ||
} |
47 changes: 0 additions & 47 deletions
47
android/src/main/java/io/swan/rnbrowser/RNSwanBrowserPackage.java
This file was deleted.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
android/src/main/java/io/swan/rnbrowser/RNSwanBrowserPackage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package io.swan.rnbrowser | ||
|
||
import com.facebook.react.TurboReactPackage | ||
import com.facebook.react.bridge.NativeModule | ||
import com.facebook.react.bridge.ReactApplicationContext | ||
import com.facebook.react.module.model.ReactModuleInfo | ||
import com.facebook.react.module.model.ReactModuleInfoProvider | ||
|
||
class RNSwanBrowserPackage : TurboReactPackage() { | ||
|
||
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? { | ||
return when (name) { | ||
RNSwanBrowserModuleImpl.NAME -> RNSwanBrowserModule(reactContext) | ||
else -> null | ||
} | ||
} | ||
|
||
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider { | ||
return ReactModuleInfoProvider { | ||
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap() | ||
val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED | ||
|
||
val moduleInfo = ReactModuleInfo( | ||
RNSwanBrowserModuleImpl.NAME, | ||
RNSwanBrowserModuleImpl.NAME, | ||
false, | ||
false, | ||
true, | ||
false, | ||
isTurboModule | ||
) | ||
|
||
moduleInfos[RNSwanBrowserModuleImpl.NAME] = moduleInfo | ||
moduleInfos | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
android/src/main/java/io/swan/rnbrowser/helpers/CustomTabActivityHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
android/src/main/java/io/swan/rnbrowser/helpers/CustomTabsHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
android/src/main/java/io/swan/rnbrowser/helpers/ServiceConnection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
android/src/main/java/io/swan/rnbrowser/helpers/ServiceConnectionCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.