Felipe Neves
Felipe Neves

Reputation: 957

AdjustResize in Jetpack Compose not working

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
     }
     
   }
}

Upvotes: 16

Views: 12197

Answers (2)

Gaurav Gujjar
Gaurav Gujjar

Reputation: 406

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

Modifier.imePadding()

Upvotes: 9

nglauber
nglauber

Reputation: 24024

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

Upvotes: 8

Related Questions