AdjustResize on jetpack compose not working
E

2

15

I'm implementing a screen on my project using jetpack compose (1.0.0-beta09) but I'm facing a issue on a screen with a footer that need to be always visible, even the keyboard is opened, I know that we have 'adjustResize' on android that solve this problem in a normal activity (I've a lot of screens with this footer type and it's working), but on compose if I put adjustResize on manifest or on the onCreate method of the activity the keyboard continue hiding the footer:

That's my screen without the keyboard opened, just to figure what I'm talking about

That's my screen without the keyboard opened, just to figure what I'm talking about

And that's the screen with the keyboard opened

And that's the screen with the keyboard opened

The manifest activity tag, I'm trying to open the screen with the keyboard already opened and the footer visible above him:

<activity
            android:name=".presentation.creation.billing.NewBookingBillingActivity"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTask"
            android:screenOrientation="portrait"
            android:theme="@style/AppThemeBase.Compose"
            android:windowSoftInputMode="stateVisible|adjustResize"/>

onCreate method:

override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        injectFeature()
        initView()

        window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)
        
        setContent {
            BuildScreen()
        }
    }

I know that's redundant use setSoftInputMode on manifest and on onCreate, but I'm trying anything.

-

My screen compose scope:

Column(fillMaxSize){
 - AppBar
 - Box(fillMaxSize){
      //lazycolumn used to enable scroll with bottom padding to prevent last item to be hided below the footer
     - LazyColumn(fillMaxSize | contentPadding) {
        //TextFields of the screen
     }
    
    //footer
     - Box(fillMaxWidth | height 53 | align.centerBottom){
        //footer content
     }
     
   }
}
Exclamatory answered 19/7, 2021 at 12:32 Comment(2)
Did you have a look at the Insets library that deals with this? google.github.io/accompanist/insetsStripling
Did you find solution?Loose
M
8

I guess the problem is in your LazyColumn modifier. if you set weight to 1f. It will work.

Column(Modifier.fillMaxSize()) {
    TextField(value = "", onValueChange = {})
    TextField(value = "", onValueChange = {})
    LazyColumn(Modifier.weight(1f)) {

    }
    Row {
       Button(onClick = { /*TODO*/ }) {
           Text(text = "Ok")
       }
    }
}

Here's the result:

enter image description here

Moreen answered 20/7, 2021 at 14:9 Comment(4)
weight has been removed, any way to do this nowadays?Wolter
The answer above still working on compose 1.2.0-beta02. The weight modifier was not removed... :/Moreen
You are right, got a cached old version :(Wolter
Check my answer, its more viable then this overworkLefthand
L
8

Found the perfect answer for this. In v1.8.0 or above compose we can just add below line to main composable

Modifier.imePadding()
Lefthand answered 23/1 at 7:7 Comment(1)
Completely correct. Works like a charm in combination with android:windowSoftInputMode="adjustResize"Laurinda

© 2022 - 2024 — McMap. All rights reserved.