Git Product home page Git Product logo

Comments (11)

chrisbanes avatar chrisbanes commented on April 20, 2024 2

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.

chrisbanes avatar chrisbanes commented on April 20, 2024 2

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.

chrisbanes avatar chrisbanes commented on April 20, 2024

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.

qrezet avatar qrezet commented on April 20, 2024

Hi, I have an even problematic scenario about managing the same thing.

The problem is that, my TextFields 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.

qrezet avatar qrezet commented on April 20, 2024

Thanks @chrisbanes

from accompanist.

radzio avatar radzio commented on April 20, 2024

@qrezet have you find any solution or workaround to your problem

from accompanist.

github-actions avatar github-actions commented on April 20, 2024

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.

burhankhanzada avatar burhankhanzada commented on April 20, 2024

it doesn't work for me

from accompanist.

b95505017 avatar b95505017 commented on April 20, 2024

@chrisbanes It works with latest 1.0.0, but no effect with latest snapshot version. 😢

from accompanist.

chrisbanes avatar chrisbanes commented on April 20, 2024

I think something is currently broken with RelocationRequester & LazyColumn. Not much we can do at this point.

from accompanist.

github-actions avatar github-actions commented on April 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.