Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Paywalls V2] Adds Custom Tabs to support in-app browser URL destinations #2035

Merged
merged 36 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
8a0c1d0
Adds an optional previewImageLoader parameter.
JayShortway Jan 6, 2025
d26ee92
Adds and uses aspect ratio to aid layout when one axis is Fit.
JayShortway Jan 6, 2025
7b18c1d
Fixes cyclomatic complexity.
JayShortway Jan 6, 2025
313af7e
Fixes the gradient previews.
JayShortway Jan 6, 2025
a6959c2
Marks DrawablePainter as experimental.
JayShortway Jan 7, 2025
a4d626b
Handles gradient percentages in the 0..100 range.
JayShortway Jan 7, 2025
1adb3e8
Splits restore logic to handleRestorePurchases and calls it from hand…
JayShortway Jan 7, 2025
734faad
Calls handlePackagePurchase from handleAction.
JayShortway Jan 7, 2025
be64ae6
Calls closePaywall from handleAction.
JayShortway Jan 7, 2025
09be9d4
Moves click handling to the Composable for easier navigation handling.
JayShortway Jan 7, 2025
6e9a0c5
Fixes PaywallActionTests.
JayShortway Jan 7, 2025
f57414e
Handles URL button destinations.
JayShortway Jan 8, 2025
7410ee4
Updates compose-bom to 2024.09.00.
JayShortway Jan 7, 2025
609550e
Fixes Markdown consuming all click actions, even without links.
JayShortway Jan 7, 2025
b115f58
Adds another strikethrough preview.
JayShortway Jan 7, 2025
8908a6b
Fixes PaywallActionTests.
JayShortway Jan 8, 2025
1d10bad
Merge branch 'pw2-fix-text-button-click-consumption' into pw2-button-…
JayShortway Jan 8, 2025
0d41211
Merge branch 'main' into pw2-gradient-percent-scale
JayShortway Jan 8, 2025
727d7e8
Merge branch 'pw2-gradient-percent-scale' into pw2-fix-text-button-cl…
JayShortway Jan 8, 2025
3065b4f
Merge branch 'pw2-fix-text-button-click-consumption' into pw2-button-…
JayShortway Jan 8, 2025
87bc1a9
Adds Custom Tabs to support in-app browser URL destinations.
JayShortway Jan 8, 2025
460dff3
Merge branch 'main' into pw2-fix-text-button-click-consumption
JayShortway Jan 8, 2025
97a439d
Merge branch 'pw2-fix-text-button-click-consumption' into pw2-button-…
JayShortway Jan 8, 2025
0d2f2f0
Merge branch 'pw2-button-actions' into pw2-in-app-browser
JayShortway Jan 8, 2025
cc1b11a
Merge branch 'main' into pw2-button-actions
JayShortway Jan 8, 2025
40c3b61
Merge branch 'pw2-button-actions' into pw2-in-app-browser
JayShortway Jan 8, 2025
3684f8b
Uncomments the same thing again.
JayShortway Jan 8, 2025
43c0725
Merge branch 'pw2-button-actions' into pw2-in-app-browser
JayShortway Jan 8, 2025
a0be258
Fixes tests.
JayShortway Jan 9, 2025
2ee2941
Merge branch 'main' into pw2-button-actions
JayShortway Jan 9, 2025
6eb73b4
Merge branch 'pw2-button-actions' into pw2-in-app-browser
JayShortway Jan 9, 2025
e47e725
Merge branch 'main' into pw2-in-app-browser
JayShortway Jan 9, 2025
e5471b0
Merge branch 'main' into pw2-in-app-browser
JayShortway Jan 9, 2025
e1d2ed4
Merge branch 'main' into pw2-in-app-browser
JayShortway Jan 10, 2025
63ce86f
Merge branch 'main' into pw2-in-app-browser
JayShortway Jan 13, 2025
b0f547f
Catches known exceptions only.
JayShortway Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ poko = { id = "dev.drewhamilton.poko", version = "0.13.1" }
[libraries]
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
androidx-annotation = { module = "androidx.annotation:annotation", version.ref = "annotation" }
androidx-browser = { module = "androidx.browser:browser", version = "1.8.0" }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be very light on runtime dependencies, which decreases the risk of binary incompatibilities.

androidx-constraintlayout = "androidx.constraintlayout:constraintlayout:2.1.3"
androidx-core = { module = "androidx.core:core-ktx", version.ref = "androidxCore" }
androidx-datastore-preferences = "androidx.datastore:datastore-preferences:1.0.0"
Expand Down
1 change: 1 addition & 0 deletions ui/revenuecatui/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ dependencies {
implementation libs.activity.compose
implementation libs.androidx.fragment.ktx
implementation libs.compose.ui.google.fonts
implementation libs.androidx.browser
debugImplementation libs.compose.ui.tooling
debugImplementation libs.androidx.test.compose.manifest

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import android.content.ActivityNotFoundException
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Configuration
import android.net.Uri
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.browser.customtabs.CustomTabsIntent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
Expand Down Expand Up @@ -288,19 +290,31 @@ private fun rememberPaywallActionHandler(viewModel: PaywallViewModel): suspend (
}

private fun Context.handleUrlDestination(url: String, method: ButtonComponent.UrlMethod) {
fun handleException(exception: Exception) {
val message = if (exception is ActivityNotFoundException) {
getString(R.string.no_browser_cannot_open_link)
} else {
getString(R.string.cannot_open_link)
}
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
Logger.e(message, exception)
}

when (method) {
ButtonComponent.UrlMethod.IN_APP_BROWSER -> TODO()
ButtonComponent.UrlMethod.EXTERNAL_BROWSER,
ButtonComponent.UrlMethod.DEEP_LINK,
-> openUriOrElse(url) { exception ->
val message = if (exception is ActivityNotFoundException) {
getString(R.string.no_browser_cannot_open_link)
} else {
getString(R.string.cannot_open_link)
ButtonComponent.UrlMethod.IN_APP_BROWSER -> {
val intent = CustomTabsIntent.Builder()
.build()
@Suppress("TooGenericExceptionCaught")
try {
intent.launchUrl(this, Uri.parse(url))
} catch (e: Exception) {
handleException(e)
}
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
Logger.w(message)
}

ButtonComponent.UrlMethod.EXTERNAL_BROWSER,
ButtonComponent.UrlMethod.DEEP_LINK,
-> openUriOrElse(url, ::handleException)
}
}

Expand Down