Comments (11)
I don't think this is supported yet (but I'll ask the team later). I just saw that someone raised this bug which is very related.
from accompanist.
The recent RelocationRequester
API should allow us to do this. Just spent 10 mins and come up with this:
@ExperimentalComposeUiApi
fun Modifier.bringIntoViewAfterImeAnimation(): Modifier = composed {
val imeInsets = LocalWindowInsets.current.ime
var focusState by remember { mutableStateOf<FocusState?>(null) }
val relocationRequester = remember { RelocationRequester() }
LaunchedEffect(
imeInsets.isVisible,
imeInsets.animationInProgress,
focusState,
relocationRequester
) {
if (imeInsets.isVisible &&
!imeInsets.animationInProgress &&
focusState?.isFocused == true) {
relocationRequester.bringIntoView()
}
}
relocationRequester(relocationRequester)
.onFocusChanged { focusState = it }
}
var textField by remember { mutableStateOf(TextFieldValue()) }
TextField(
value = textField,
onValueChange = { textField = it },
modifier = Modifier.bringIntoViewAfterImeAnimation()
)
It's not perfect, but it should form the basis of a solution. The idea is that each focusable item needs to be responsible for requesting that it is visible when necessary. The only difference from the usual logic is that we need to wait for any IME animations to finish before requesting.
Note: RelocationRequester
seems to currently only work with scrolling Column
or Row
(i.e. not LazyColumn
, etc)
from accompanist.
Hmmm, using smoothScrollToItem()
is probably the right thing here. I don't think this will ever be automatic, since the Modifier
has no idea about any other composables around it.
I think we might be missing a callback from the modifier to know when to call smoothScrollToItem
though.
FYI, I think you'll have better luck with laying out from the bottom:
Column(
modifier = Modifier
// other modifiers
.verticalScroll(scrollState, reverseScrolling = true),
verticalArrangement = Arrangement.Bottom,
)
Laying out from the bottom means that the scroll position should remain the same as the Column
changes size.
from accompanist.
Hi, I have an even problematic scenario about managing the same thing.
The problem is that, my TextField
s are inside Column
which is inside LazyColumn
's item()
.
I could call LazyState.animateScrollToItem()
but I don't know how to get the correct Offset
to properly position the focused TextField
.
Do you guys have any idea how to do this?
from accompanist.
Thanks @chrisbanes
from accompanist.
@qrezet have you find any solution or workaround to your problem
from accompanist.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
from accompanist.
it doesn't work for me
from accompanist.
@chrisbanes It works with latest 1.0.0, but no effect with latest snapshot version. 😢
from accompanist.
I think something is currently broken with RelocationRequester
& LazyColumn
. Not much we can do at this point.
from accompanist.
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.
from accompanist.
Related Issues (20)
- [WebView] Doesn't save state when recycled in a LazyColumn HOT 2
- [WebView] Question about backwards writes HOT 5
- Vector animation is broken with newer libraries HOT 4
- False positive deprecation message on pagerTabIndicatorOffset variant HOT 2
- onPermissionsResult isn't triggered on POST_NOTIFICATIONS permission request (API 33). HOT 2
- [Test Harness] Deprecate with replacement of `DeviceConfigurationOverride`
- Incorrect deprecation of pagerTabIndicatorOffset HOT 1
- [Permissions] Gradle update crashing permission request and the app HOT 8
- Crash when using ProgressIndicator with `accompanist-permissions` 0.34.0 HOT 1
- [Navigation Material] Crash in BottomSheetNavigator when user goes back HOT 3
- [Navigation Material] Status bar not scrimmed when bottom sheet is shown HOT 1
- [LazyColumn] scroll observation scope does not exist HOT 2
- [Feature request] LazyTable with nested scrolling support HOT 1
- [Navigation Material] Edge to edge jumping bug when migrating from 1.1.2 to 1.2.0. HOT 1
- [Navigation Material] BackHandler is not triggered after Activity stop+start HOT 1
- [Navigation Material] DisposableEffect onDispose is not called at the right time for bottom sheet HOT 1
- [Navigation Material] Add deprecated to main README
- [Adaptive]
- accompanist-drawablepainter: PictureDrawable doesn't scale HOT 1
- BottomSheetNavigator#NullPointerException
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from accompanist.