Status Update
Comments
jb...@google.com <jb...@google.com> #2
Branch: androidx-master-dev
commit c60f33e229e31ab328ef6b59dab63b264954831c
Author: Alexandre Elias <aelias@google.com>
Date: Fri Jul 10 16:23:09 2020
Semantics no-op cleanups
Partly in response to lmr's broad code review, I did a pass of
superficial API/implementation cleanup. The main changes are:
- I changed each Boolean SemanticsProperty where false is equivalent to
not being present to take "Unit" instead. This is conceptually
clearer: it avoids questions like "can I cancel out a semantics from a
merged child by setting it to false?" Because "property = Unit" looks
weird, I also changed the style of these to "property()".
- I moved the Semantics id generator closer to where it's used, in
SemanticsModifierCore. I made it internal and an AtomicInt.
(Note that integer ids are heavily used in the Android
AccessibilityNodeInfo APIs so I can't simply remove them entirely.)
- I deleted dead code. Some examples include SemanticsHintOverrides,
a public API not connected to anything, and SemanticsPropertyKey
merge() open method which is never called. (In both cases I have
a different plan in mind for accessibility.)
Fixes: 145951226
Fixes: 145955412
Test: existing tests
Relnote: "Single-value semantics properties now use a calling style.
For example, 'semantics { hidden = true }' is now written as:
'semantics { hidden() }'."
Change-Id: Ic1afd12ea22c926babc9662f1804d80b33aa0cfc
M ui/integration-tests/benchmark/src/androidTest/java/androidx/ui/benchmark/test/LayoutNodeModifierBenchmark.kt
M ui/ui-core/api/0.1.0-dev15.txt
M ui/ui-core/api/current.txt
M ui/ui-core/api/public_plus_experimental_0.1.0-dev15.txt
M ui/ui-core/api/public_plus_experimental_current.txt
M ui/ui-core/api/restricted_0.1.0-dev15.txt
M ui/ui-core/api/restricted_current.txt
M ui/ui-core/src/androidAndroidTest/kotlin/androidx/ui/graphics/vector/VectorTest.kt
M ui/ui-core/src/androidAndroidTest/kotlin/androidx/ui/semantics/SemanticsTests.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/AndroidActuals.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/AndroidComposeView.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/AndroidComposeViewAccessibilityDelegateCompat.kt
M ui/ui-core/src/androidMain/kotlin/androidx/ui/core/AndroidPopup.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/core/Expect.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/core/semantics/SemanticsConfiguration.kt
D ui/ui-core/src/commonMain/kotlin/androidx/ui/core/semantics/SemanticsHintOverrides.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/core/semantics/SemanticsModifier.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/core/semantics/SemanticsNode.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/core/semantics/SemanticsOwner.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/core/semantics/SemanticsWrapper.kt
M ui/ui-core/src/commonMain/kotlin/androidx/ui/semantics/SemanticsProperties.kt
M ui/ui-foundation/api/0.1.0-dev15.txt
M ui/ui-foundation/api/current.txt
M ui/ui-foundation/api/public_plus_experimental_0.1.0-dev15.txt
M ui/ui-foundation/api/public_plus_experimental_current.txt
M ui/ui-foundation/api/restricted_0.1.0-dev15.txt
M ui/ui-foundation/api/restricted_current.txt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Clickable.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Dialog.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/Scroller.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/selection/Selectable.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/selection/Toggleable.kt
M ui/ui-foundation/src/main/java/androidx/ui/foundation/semantics/FoundationSemanticsProperties.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/ButtonTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/CardTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/CheckboxScreenshotTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/RadioButtonScreenshotTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/ScaffoldTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/SnackbarTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/SurfaceTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/ripple/RippleIndicationTest.kt
M ui/ui-material/src/androidTest/java/androidx/ui/material/textfield/TextFieldScreenshotTest.kt
M ui/ui-material/src/main/java/androidx/ui/material/AppBar.kt
M ui/ui-material/src/main/java/androidx/ui/material/TextFieldImpl.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/AssertsTest.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/CallSemanticsActionTest.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/ErrorMessagesTest.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/FindersTest.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/PrintToStringTest.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/ScrollToTest.kt
M ui/ui-test/src/androidTest/java/androidx/ui/test/TextActionsTest.kt
M ui/ui-test/src/main/java/androidx/ui/test/Actions.kt
M ui/ui-test/src/main/java/androidx/ui/test/Filters.kt
M ui/ui-text/api/0.1.0-dev15.txt
M ui/ui-text/api/current.txt
M ui/ui-text/api/public_plus_experimental_0.1.0-dev15.txt
M ui/ui-text/api/public_plus_experimental_current.txt
M ui/ui-text/api/restricted_0.1.0-dev15.txt
M ui/ui-text/api/restricted_current.txt
M ui/ui-text/src/commonMain/kotlin/androidx/ui/text/CoreTextField.kt
M ui/ui-text/src/commonMain/kotlin/androidx/ui/text/TextSemanticsProperties.kt
ju...@gmail.com <ju...@gmail.com> #3
Yes, I am familiar with AndroidViewBinding, however, as far as I know it has some limitations, like, I can't decide at runtime what fragment to commit.
ju...@gmail.com <ju...@gmail.com> #4
I also can't give parameters to the fragment being inflated.
ap...@google.com <ap...@google.com> #5
Branch: androidx-main
commit ffe9335a155bf0dea9c3558e50da01d526579040
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Mar 26 20:24:54 2024
Create AndroidFragment to allow adding fragments in Compose
Adding new AndroidFragment API that creates the given Fragment class and
adds it to the enclosing FragmentManager, within Compose.
It handles setting the ViewCompositionStrategy and saving the state of
the fragment across recompositions.
RelNote: "The new AndroidFragment Composable allows adding fragments
into the Compose hierarchy via the fragment class name."
Test: added AndroidFragmentTest
Bug: 230126482
Bug: 312895363
Change-Id: Icf84199bbe487b2a2b6a95d2b6e09415f810e77a
M docs-tip-of-tree/build.gradle
M fragment/fragment-compose/api/current.txt
M fragment/fragment-compose/api/restricted_current.txt
M fragment/fragment-compose/build.gradle
A fragment/fragment-compose/samples/build.gradle
A fragment/fragment-compose/samples/src/main/java/androidx/fragment/compose/samples/FragmentComposeSamples.kt
M fragment/fragment-compose/src/androidTest/AndroidManifest.xml
A fragment/fragment-compose/src/androidTest/java/androidx/fragment/compose/AndroidFragmentTest.kt
A fragment/fragment-compose/src/androidTest/java/androidx/fragment/compose/FragmentRecreateTest.kt
A fragment/fragment-compose/src/androidTest/java/androidx/fragment/compose/FragmentRemoveTest.kt
A fragment/fragment-compose/src/androidTest/java/androidx/fragment/compose/SimpleEditTextFragment.kt
A fragment/fragment-compose/src/androidTest/java/androidx/fragment/compose/test/EmptyTestActivity.kt
A fragment/fragment-compose/src/androidTest/res/layout/content.xml
A fragment/fragment-compose/src/androidTest/res/layout/sample_edit_test_layout.xml
A fragment/fragment-compose/src/main/java/androidx/fragment/compose/AndroidFragment.kt
A fragment/fragment-compose/src/main/java/androidx/fragment/compose/FragmentState.kt
M fragment/fragment/api/current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentTransaction.java
M settings.gradle
ju...@veepee.com <ju...@veepee.com> #6
Hey, Thanks to checking this out, I just checked this sample in the the repository, but this does not solve my issue.
I don't have access to the actual fragment class, we use an abstraction that just returns me a instance of Fragment with the arguments set, so this won't solve the issue for me, would it be possible to allow passing the Fragment instance ?
il...@google.com <il...@google.com> #7
Re
This aligns with other fragment based APIs like FragmentScenario
and NavHostFragment
. You'll want to adjust your own abstraction to use those APIs and separate the creation of the fragment instance from the arguments.
il...@google.com <il...@google.com> #8
I'll note that FragmentFactory does allow you to request an AbstractBaseFragment
and redirect it to a specific subclass of that class without exposing that subclass itself if you do need that level of indirection.
ju...@veepee.com <ju...@veepee.com> #9
We were always allowed to create a new Fragment and to commit a Fragment instance in FragmentManager, could you align with that as well? My abstraction returns a Fragment instance because this allows us to avoid directly depending on the gradle module that provides the Fragment and this strategy improves compilation time by making the gradle dependency graph flatter.
il...@google.com <il...@google.com> #10
You'll want your abstraction to be implemented in terms of a FragmentFactory.
ju...@veepee.com <ju...@veepee.com> #11
My abstraction does not use fragmentFactory, and don't need to. How is that related to this issue? Devs have always been able to instantiate a fragment using default fragment constructor, I am not exposing which Fragment subclass is being instantiated in the calling site or using the className as key to find which fragment to instantiate, to add a fragment to FragmentManager we just need the base class Fragment.
ba...@gmail.com <ba...@gmail.com> #12
il...@google.com <il...@google.com> #13
Re AndroidFragment
with key(url)
to reset that subtree whenever url
changes.
ba...@gmail.com <ba...@gmail.com> #14
Thanks, using key(url)
works like a charm. I thought this function was only available for LazyList|Column
...
ba...@gmail.com <ba...@gmail.com> #15
For your information we have the following crash using AndroidView
:
Exception java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at androidx.fragment.app.FragmentManager.checkStateLoss (FragmentManager.java:1) at androidx.fragment.app.FragmentManager.ensureExecReady (FragmentManager.java:1) at androidx.fragment.app.FragmentManager.execSingleAction (FragmentManager.java:1) at androidx.fragment.app.BackStackRecord.commitNow (BackStackRecord.java:1) at androidx.fragment.compose.AndroidFragmentKt$AndroidFragment$4.invoke (AndroidFragment.kt:110) at androidx.fragment.compose.AndroidFragmentKt$AndroidFragment$4.invoke (AndroidFragment.kt:3) at androidx.compose.runtime.DisposableEffectImpl.onRemembered (Effects.kt:7) at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers (Composition.kt:144) at androidx.compose.runtime.CompositionImpl.applyChangesInLocked (Composition.kt:1) at androidx.compose.runtime.CompositionImpl.applyChanges (Composition.kt:6) at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke (Recomposer.kt:1) at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke (Recomposer.kt:7) at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame (AndroidUiFrameClock.android.kt:11) at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch (AndroidUiDispatcher.android.kt:34) at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch (AndroidUiDispatcher.android.kt:1) at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame (AndroidUiDispatcher.android.kt:17) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1229) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1239) at android.view.Choreographer.doCallbacks (Choreographer.java:899) at android.view.Choreographer.doFrame (Choreographer.java:827) at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1214) at android.os.Handler.handleCallback (Handler.java:942) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:201) at android.os.Looper.loop (Looper.java:288) at android.app.ActivityThread.main (ActivityThread.java:7918) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)
lo...@gmail.com <lo...@gmail.com> #16
Will there also be an overload in which we can directly pass in an already created fragment instance? Like:
fun <T : Fragment> AndroidFragment(
fragment: T,
modifier: Modifier = Modifier,
fragmentState: FragmentState = rememberFragmentState(),
arguments: Bundle = Bundle.EMPTY,
onUpdate: (T) -> Unit = { },
) { ... }
il...@google.com <il...@google.com> #17
Re
il...@google.com <il...@google.com> #18
Re
Description
What is the correct strategy to restoring a fragment commited inside a compose AndroidView? I would expect that something like the example below to be enough to handle the fragment state restoration in an orientation change, but when rotating the screen the fragment is no longer drawn.
It would be nice to have a composable version of
FragmentContainerView
that could handle Fragment state restoration properly.