Fixed
Status Update
Comments
le...@google.com <le...@google.com>
ap...@google.com <ap...@google.com> #2
It is expected that BackHandler
crashes in cases where no LocalOnBackPressedDispatcherOwner
Given that LocalOnBackPressedDispatcherOwner.current
is nullable, you can certainly wrap your call to BackHandler
in a null check if you'd like to specifically disable that functionality when in @Preview
. Of course, you could just provide your own OnBackPressedDispatcherOwner
by constructing an OnBackPressedDispatcher
instance yourself as part of your @Preview
.
Andrey - any thoughts on whether we should have @Preview
automatically create and set a LocalOnBackPressedDispatcherOwner
as we do for LocalViewModelStoreOwner
nj...@google.com <nj...@google.com> #3
If you think you want to provide some fake implementation for previews you probably want to provide it somewhere here: https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt;l=478;drc=38caeffe2a32b6135f231b83c54b109e30bcd474 , and ask Diego for a review.
Note that in previews we do not really support ViewModels in reality. We provide a fake ViewModelStoreOwner, but this implementation just crashes when you try to create a ViewModel. It was a Sergey's idea as usually ViewModels are doing some network/database requests and we don't really support it in the preview mode.
Note that in previews we do not really support ViewModels in reality. We provide a fake ViewModelStoreOwner, but this implementation just crashes when you try to create a ViewModel. It was a Sergey's idea as usually ViewModels are doing some network/database requests and we don't really support it in the preview mode.
ap...@google.com <ap...@google.com> #4
Project: platform/frameworks/support
Branch: androidx-main
commit 026203513c5a704abeaa34595e7a7e7ab06876f7
Author: Ian Lake <ilake@google.com>
Date: Mon Jun 14 11:47:14 2021
Add an ActivityResultRegistry to Compose Previews
An ActivityResultRegistry is provided by default
by ComponentActivity, but using APIs that depend on
it, like rememberLauncherForActivityResult() would
crash in @Preview. By adding a fake implementation,
developers can preview those Composables.
For cases where they call `launch()` (i.e., the
`startActivityForResult()` equivalent), the fake
throws an IllegalStateException to indicate that
actually starting an activity / permission request
in Preview is not supported.
Relnote: "Compose `@Preview` now provides a
`LocalActivityResultRegistryOwner` that allows you
to preview Composables that use APIs like
`rememberLauncherForActivityResult()` that depend
on that owner existing."
Test: new ComposeViewAdapterTest test passes
BUG: 185693006
Change-Id: Ib13d12f085065adb89cfb731179b9295029e06e9
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/SimpleComposablePreview.kt
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
M compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
https://android-review.googlesource.com/1737073
Branch: androidx-main
commit 026203513c5a704abeaa34595e7a7e7ab06876f7
Author: Ian Lake <ilake@google.com>
Date: Mon Jun 14 11:47:14 2021
Add an ActivityResultRegistry to Compose Previews
An ActivityResultRegistry is provided by default
by ComponentActivity, but using APIs that depend on
it, like rememberLauncherForActivityResult() would
crash in @Preview. By adding a fake implementation,
developers can preview those Composables.
For cases where they call `launch()` (i.e., the
`startActivityForResult()` equivalent), the fake
throws an IllegalStateException to indicate that
actually starting an activity / permission request
in Preview is not supported.
Relnote: "Compose `@Preview` now provides a
`LocalActivityResultRegistryOwner` that allows you
to preview Composables that use APIs like
`rememberLauncherForActivityResult()` that depend
on that owner existing."
Test: new ComposeViewAdapterTest test passes
BUG: 185693006
Change-Id: Ib13d12f085065adb89cfb731179b9295029e06e9
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/SimpleComposablePreview.kt
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
M compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
na...@google.com <na...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit 622947a991ba924d4896965f708be022bf1b35ba
Author: Ian Lake <ilake@google.com>
Date: Mon Jun 14 11:34:13 2021
Add a fake OnBackPressedDispatcher to Compose Previews
Rather than having APIs that depend on
LocalOnBackPressedDispatcher crash in @Preview,
provide a fake implementation by default to mirror
the capabilities that are available by default
in a ComponentActivity.
Relnote: "Compose `@Preview` now provides a
`LocalOnBackPressedDispatcherOwner` that allows you
to preview Composables that use APIs like `BackHandler`
that depend on that owner existing."
Test: new ComposeViewAdapterTest test passes
BUG: 185693006
Change-Id: Ia1c05ea3cadf2fb55cef9c4b8bae0898cfb35ba9
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/SimpleComposablePreview.kt
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
M compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
https://android-review.googlesource.com/1736795
Branch: androidx-main
commit 622947a991ba924d4896965f708be022bf1b35ba
Author: Ian Lake <ilake@google.com>
Date: Mon Jun 14 11:34:13 2021
Add a fake OnBackPressedDispatcher to Compose Previews
Rather than having APIs that depend on
LocalOnBackPressedDispatcher crash in @Preview,
provide a fake implementation by default to mirror
the capabilities that are available by default
in a ComponentActivity.
Relnote: "Compose `@Preview` now provides a
`LocalOnBackPressedDispatcherOwner` that allows you
to preview Composables that use APIs like `BackHandler`
that depend on that owner existing."
Test: new ComposeViewAdapterTest test passes
BUG: 185693006
Change-Id: Ia1c05ea3cadf2fb55cef9c4b8bae0898cfb35ba9
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/SimpleComposablePreview.kt
M compose/ui/ui-tooling/src/androidAndroidTest/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapterTest.kt
M compose/ui/ui-tooling/src/androidMain/kotlin/androidx/compose/ui/tooling/preview/ComposeViewAdapter.kt
Description
Uncomment androidx.annotation annotations in graphics common code so developers get working lint checks: