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

Update to Compose 1.5.1 #7297

Merged
merged 4 commits into from
Sep 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
### PaymentSheet
* [ADDED][7302](https://github.com/stripe/stripe-android/pull/7302) PaymentSheet now supports Alma for PaymentIntents in private beta.

Dependencies updated:
* [7297](https://github.com/stripe/stripe-android/pull/7297) Bumped Compose Foundation, Compose Material, Compose Runtime, and Compose UI from 1.4.3 to 1.5.1.

## 20.30.2 - 2023-09-13

### PaymentSheet
Expand Down
9 changes: 9 additions & 0 deletions build-configuration/android-application.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ apply from: rootProject.file('build-configuration/ktlint.gradle')

check.dependsOn('ktlint')

configurations {
configureEach {
resolutionStrategy {
// Not depending on 1.4.0 because it requires compile SDK 34
force 'androidx.emoji2:emoji2:1.3.0'
}
}
}

android {
namespace STRIPE_ANDROID_NAMESPACE
compileSdkVersion rootProject.ext.compileSdkVersion
Expand Down
6 changes: 6 additions & 0 deletions build-configuration/android-library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ check.dependsOn('ktlint')

configurations {
javadocDeps
configureEach {
resolutionStrategy {
// Not depending on 1.4.0 because it requires compile SDK 34
force 'androidx.emoji2:emoji2:1.3.0'
}
}
}

if (System.getenv("JITPACK")) {
Expand Down
7 changes: 3 additions & 4 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ ext.versions = [
androidxAppcompat : '1.6.1',
androidxArchCore : '2.2.0',
androidxBrowser : '1.5.0',
androidxCompose : '1.4.3',
androidxCompose : '1.5.1',
androidxComposeCompiler : '1.4.1',
androidxComposeRuntime : '1.4.3',
androidxComposeUi : '1.4.3',
androidxComposeRuntime : '1.5.1',
androidxComposeUi : '1.5.1',
androidxConstraintlayout : '2.1.4',
androidxCore : '1.9.0',
androidxFragment : '1.5.5',
Expand All @@ -25,7 +25,6 @@ ext.versions = [
androidxRecyclerview : '1.2.1',
androidxSecurity : '1.1.0-alpha05',
binaryCompatibilityValidator: '0.13.1',
buildTools : "30.0.3",
cameraX : '1.2.3',
dagger : '2.48',
detekt : "1.22.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal const val BottomSheetContentTestTag = "BottomSheetContentTestTag"
internal class BottomSheetState(
val modalBottomSheetState: ModalBottomSheetState,
val keyboardHandler: BottomSheetKeyboardHandler,
val sheetGesturesEnabled: Boolean,
) {

private var dismissalType: DismissalType? = null
Expand Down Expand Up @@ -101,6 +102,7 @@ internal fun rememberBottomSheetState(
BottomSheetState(
modalBottomSheetState = modalBottomSheetState,
keyboardHandler = keyboardHandler,
sheetGesturesEnabled = false,
)
}
}
Expand Down Expand Up @@ -172,6 +174,7 @@ internal fun BottomSheet(
topStart = MaterialTheme.stripeShapes.cornerRadius.dp,
topEnd = MaterialTheme.stripeShapes.cornerRadius.dp,
),
sheetGesturesEnabled = state.sheetGesturesEnabled,
sheetContent = {
Box(modifier = Modifier.testTag(BottomSheetContentTestTag)) {
sheetContent()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package com.stripe.android.common.ui

import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.ime
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.platform.SoftwareKeyboardController
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import kotlinx.coroutines.flow.first

@OptIn(ExperimentalComposeUiApi::class)
Expand All @@ -35,20 +33,8 @@ internal class BottomSheetKeyboardHandler(
@OptIn(ExperimentalComposeUiApi::class)
@Composable
internal fun rememberBottomSheetKeyboardHandler(): BottomSheetKeyboardHandler {
val view = LocalView.current
val isImeVisible = remember { mutableStateOf(false) }

DisposableEffect(view) {
ViewCompat.setOnApplyWindowInsetsListener(view) { _, insets ->
isImeVisible.value = insets.isVisible(WindowInsetsCompat.Type.ime())
insets
}

onDispose {
ViewCompat.setOnApplyWindowInsetsListener(view, null)
}
}

val imeHeight = WindowInsets.ime.getBottom(LocalDensity.current)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This does seem to work on API 29 🤔

val isImeVisibleState = rememberUpdatedState(newValue = imeHeight > 0)
val keyboardController = LocalSoftwareKeyboardController.current
return BottomSheetKeyboardHandler(keyboardController, isImeVisible)
return BottomSheetKeyboardHandler(keyboardController, isImeVisibleState)
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,7 @@ internal class AddressElementActivity : ComponentActivity() {
val navController = rememberAnimatedNavController()
viewModel.navigator.navigationController = navController

val bottomSheetState = rememberBottomSheetState(
confirmValueChange = {
val route = navController.currentDestination?.route
route != AddressElementScreen.Autocomplete.route
},
)
val bottomSheetState = rememberBottomSheetState()

BackHandler {
viewModel.navigator.onBack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.activity.compose.setContent
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.ModalBottomSheetValue
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
Expand Down Expand Up @@ -46,9 +47,18 @@ internal class PollingActivity : AppCompatActivity() {

setContent {
StripeTheme {
val state = rememberBottomSheetState(confirmValueChange = { false })
val uiState by viewModel.uiState.collectAsState()

val state = rememberBottomSheetState(
confirmValueChange = { proposedValue ->
if (proposedValue == ModalBottomSheetValue.Hidden) {
uiState.pollingState != PollingState.Active
} else {
true
}
}
)

BackHandler(enabled = true) {
if (uiState.pollingState == PollingState.Failed) {
viewModel.handleCancel()
Expand Down
1 change: 1 addition & 0 deletions stripe-ui-core/src/test/resources/robolectric.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sdk=33