Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyboard inset padding and NestedScrollView #93

Closed
GeniusRUS opened this issue Feb 9, 2021 · 7 comments
Closed

Keyboard inset padding and NestedScrollView #93

GeniusRUS opened this issue Feb 9, 2021 · 7 comments

Comments

@GeniusRUS
Copy link

GeniusRUS commented Feb 9, 2021

@chrisbanes hi!
A strange situation occurred while working with keyboard insets
If you install paddings from the keyboard for NestedScrollView, the view in focus does not remain visible, hiding behind the keyboard
How can you handle this scenario so that the EditText respects the keyboard that appears? Only by setting margins for NestedScrollView?

Activity and layout code is below

class MainActivity : AppCompatActivity(R.layout.activity_main) {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        val rootView = findViewById<LinearLayout>(R.id.root_view)
        val nestedScroll = findViewById<NestedScrollView>(R.id.nested_scroll)
        val toolbar = findViewById<Toolbar>(R.id.toolbar)

        WindowCompat.setDecorFitsSystemWindows(window, false)

        Insetter.builder().setOnApplyInsetsListener { _, insets, _ ->
            toolbar.updatePadding(
                top = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top
            )
            nestedScroll.updatePadding(
                bottom = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom + insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom
            )
        }.applyToView(rootView)
    }
}

<androidx.appcompat.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:title="@string/app_name" />

<androidx.core.widget.NestedScrollView
    android:id="@+id/nested_scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="750dp"
            android:layout_marginBottom="120dp"
            android:hint="This will be hide by the keyboard" />
    </LinearLayout>
</androidx.core.widget.NestedScrollView>
Recording_2021-02-09-12-11-05.mp4
@chrisbanes
Copy link
Owner

chrisbanes commented Feb 9, 2021

First of all, this will look a LOT better once I release the new update (which should be later this week):

toolbar.applyInsetter {
    type(statusBars = true) {
        padding(top = true)
    }
}

nestedScroll.applyInsetter {
    type(ime = true, systemBars = true) {
        padding(bottom = true)
    }
}

You can try the snapshots now.

As to the issue, does the EditText need to be in the ScrollView? If so, I'd add the ime + systemBars padding to the LinearLayout instead.

@GeniusRUS
Copy link
Author

@chrisbanes thanks for the answer. I tried to set paddings for LinearLayout, unfortunately, this did not lead to anything, I got absolutely the same behavior
I think that if NestedScrollView does not change its external dimensions in the layout, then the content in it will always ignore any padding and focused view will be also ignored

I can also provide a minimal project in order to reproduce the problem

@chrisbanes
Copy link
Owner

If you have a sample, I’ll try and take a look.

I don’t think this is anything to do with the library though, so I’ll close this.

@GeniusRUS
Copy link
Author

Thanks for the help
Here is a MVP to reproduce

Insets.zip

@chrisbanes
Copy link
Owner

Had a quick look at this. The issue is that the EditText is in the ScrollView. There's not a whole lot you can do here really as you need to also scroll the ScrollView.

@chrisbanes chrisbanes reopened this Feb 15, 2021
@GeniusRUS
Copy link
Author

Thanks for your help!
And last question:
Is there any plans for some tools to make this case work?

@chrisbanes
Copy link
Owner

No, not that I'm aware of.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants