Bug P2
Status Update
Comments
kl...@google.com <kl...@google.com>
ap...@google.com <ap...@google.com> #2
Project: platform/frameworks/support
Branch: androidx-main
commit 30ab5ff0d1840570f5628d9489b47ce118caa4a3
Author: Zach Klippenstein <klippenstein@google.com>
Date: Sat Jan 29 09:36:44 2022
Introduce onFocusBoundsChanged.
Design doc:https://docs.google.com/document/d/16VnAGMoRspc3n976hKlkxX6f9LnGkc3eYgHDF70_AoQ/edit?usp=sharing&resourcekey=0-arS4YHxpB4QN0RbdsQIehw
Note that this feature does not currently work with AndroidView ( b/220030968 ), since
that needs to be wired up in the ui module but this API is needed to fix
an issue in foundation, and I want to leave it as Experimental for now,
and we don't allow cross-module experimental access. When this modifier
is stabilized, it should be moved to UI, and that bug resolved.
Bug: b/190539358
Bug: b/192043120
Bug: b/216842427
Test: Manual via FocusedChildDemo
Test: ./gradlew :compose:f:f:cDAT
Relnote: "Introduced experimental `Modifier.onFocusedBoundsChanged` to allow
observing the bounds of child focusables."
Change-Id: I14283393b5273527ab65f4aa1a2d4383321b0d95
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Focusable.kt
M compose/foundation/foundation/api/public_plus_experimental_current.txt
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/api/restricted_current.txt
A compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/FocusedBounds.kt
A compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/FocusedBoundsDemo.kt
A compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/FocusableBoundsTest.kt
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/FoundationDemos.kt
https://android-review.googlesource.com/1965665
Branch: androidx-main
commit 30ab5ff0d1840570f5628d9489b47ce118caa4a3
Author: Zach Klippenstein <klippenstein@google.com>
Date: Sat Jan 29 09:36:44 2022
Introduce onFocusBoundsChanged.
Design doc:
Note that this feature does not currently work with AndroidView (
that needs to be wired up in the ui module but this API is needed to fix
an issue in foundation, and I want to leave it as Experimental for now,
and we don't allow cross-module experimental access. When this modifier
is stabilized, it should be moved to UI, and that bug resolved.
Bug:
Bug:
Bug:
Test: Manual via FocusedChildDemo
Test: ./gradlew :compose:f:f:cDAT
Relnote: "Introduced experimental `Modifier.onFocusedBoundsChanged` to allow
observing the bounds of child focusables."
Change-Id: I14283393b5273527ab65f4aa1a2d4383321b0d95
M compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/Focusable.kt
M compose/foundation/foundation/api/public_plus_experimental_current.txt
M compose/foundation/foundation/api/current.txt
M compose/foundation/foundation/api/restricted_current.txt
A compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/FocusedBounds.kt
A compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/FocusedBoundsDemo.kt
A compose/foundation/foundation/src/androidAndroidTest/kotlin/androidx/compose/foundation/FocusableBoundsTest.kt
M compose/foundation/foundation/integration-tests/foundation-demos/src/main/java/androidx/compose/foundation/demos/FoundationDemos.kt
sp...@gmail.com <sp...@gmail.com> #3
I'm still seeing an issue with this. Is there any update?
to...@gmail.com <to...@gmail.com> #4
Any word on this or good workarounds for windowSoftInputMode="adjustResize"? I tried some of the ones from the basic text field issue tracker and came up with the following which is good most of the time, but it being delay based is gonna be unacceptable. It can be unreliable on some devices or when there is a heavy load:
@OptIn(ExperimentalFoundationApi::class)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val listState = rememberLazyListState()
val bringIntoViewRequester = remember { BringIntoViewRequester() }
val coroutineScope = rememberCoroutineScope()
var pinnedHandle: PinnableContainer.PinnedHandle? by remember { mutableStateOf(null) }
MaterialTheme {
Surface {
LazyColumn(
modifier = Modifier.fillMaxSize(),
state = listState
) {
items(count = 20) {
val pinnableContainer = LocalPinnableContainer.current
AndroidView(
modifier = Modifier
.fillMaxWidth()
.bringIntoViewRequester(bringIntoViewRequester),
factory = { context ->
EditText(context).apply {
setText("$it")
onFocusChangeListener = View.OnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
pinnedHandle = pinnableContainer?.pin()
coroutineScope.launch {
delay(200)
bringIntoViewRequester.bringIntoView()
}
} else {
pinnedHandle?.release()
pinnedHandle = null
}
}
}
}
)
}
}
}
}
}
}
Description
The
onFocusChildPositioned
API introduced in aosp/1965665 currently ONLY works when the focused child is in the same composable, and does not work if the focused child is anAndroidView
or inside anAndroidView
, even if it's another composition inside theAndroidView
.This is because this API was required to fix an issue in the foundation module, and because it's new and still
@Experimental
needed to live in the foundation module. TheAndroidView
wiring is all done in the ui module however, and we don't allow cross-module experimental dependencies, so the android wiring couldn't happen yet.