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

Improved component bottom sheet behavior on Android. #252

Merged
merged 4 commits into from
Aug 28, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## 1.0.2

* Improved card component for large font and display sizes.
* Improved component bottom sheet behavior on Android.
* Migrated Android example to use Flutter Gradle plugins through the Plugin DSL.
* Updated iOS SDK to v5.10.0.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ import com.adyen.checkout.ui.core.AdyenComponentView
import com.adyen.checkout.ui.core.internal.ui.ViewableComponent
import com.google.android.material.bottomsheet.BottomSheetDialogFragment

class ComponentLoadingBottomSheet<T>(private val component: T) :
BottomSheetDialogFragment() where T : ViewableComponent, T : Component {
internal class ComponentLoadingBottomSheet<T> : BottomSheetDialogFragment() where T : ViewableComponent, T : Component {
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = inflater.inflate(R.layout.component_bottom_sheet_content, container, false)

@Suppress("UNCHECKED_CAST")
override fun onViewCreated(
view: View,
savedInstanceState: Bundle?
) {
view.findViewById<AdyenComponentView>(R.id.adyen_component_view)?.attach(component, viewLifecycleOwner)
isCancelable = false
// We need to cast the component because it has two types T (ViewableComponent and Component)
(component as? T)?.let {
view.findViewById<AdyenComponentView>(R.id.adyen_component_view)?.attach(it, viewLifecycleOwner)
isCancelable = false
}
}

override fun onCreateDialog(savedInstanceState: Bundle?) =
Expand All @@ -36,15 +39,18 @@ class ComponentLoadingBottomSheet<T>(private val component: T) :

companion object {
private const val TAG = "AdyenComponentLoadingBottomSheet"
private var component: Any? = null

fun <T> show(
fragmentManager: FragmentManager,
component: T
) where T : ViewableComponent, T : Component {
ComponentLoadingBottomSheet(component).show(fragmentManager, TAG)
this.component = component
ComponentLoadingBottomSheet<T>().show(fragmentManager, TAG)
}

fun hide(fragmentManager: FragmentManager) {
component = null
fragmentManager.findFragmentByTag(TAG)?.let {
(it as? BottomSheetDialogFragment)?.dismiss()
}
Expand Down
Loading