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

Sneaker appear differently in activity and fragment #40

Open
kaancelen opened this issue Jun 22, 2020 · 1 comment
Open

Sneaker appear differently in activity and fragment #40

kaancelen opened this issue Jun 22, 2020 · 1 comment

Comments

@kaancelen
Copy link

kaancelen commented Jun 22, 2020

Hi,

Sneaker appears differently from Activity and Fragment like below.
In Activity, it comes from the toolbar but in the fragment, it comes from the bottom of the toolbar.
The images are from different devices but it shows the same behavior with other devices as well.
I want both of them comes from the bottom of the toolbar as Fragment did.

Here is the AppTheme, its given in Android manifest and I didn't give any other theme to Activity.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/color_light_grey</item>
    <item name="colorPrimaryDark">@color/color_black</item>
    <item name="colorAccent">@color/color_red</item>

    <item name="android:windowContentTransitions">true</item>
</style>

Here how I show the error message, same code for both

protected fun showErrorMessage(errorMessage: String?, isGreen: Boolean = false) {
    val sneaker = Sneaker.with(this)
        .setDuration(4000)
        .autoHide(true)

    val view = LayoutInflater.from(this)
        .inflate(R.layout.view_sneaker_error, sneaker.getView(), false)

    if (isGreen) {
        view.setBackgroundColor(resources.getColor(R.color.color_green, null))
    }
    view.findViewById<TextView>(R.id.error_message).text = errorMessage

    sneaker.sneakCustom(view)
}

In Activity, FrameLayout at higher hierarchy
In Activity of Fragment,

<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:filterTouchesWhenObscured="true"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/navigation_rent"/>

</merge>

and in Fragment, XML has also FrameLayout at higher hierarchy

Activity Screenshot
Activity
Fragment Screenshot
Fragment

@ConerK
Copy link

ConerK commented Apr 12, 2021

you can fix this in Sneaker
private fun setTargetView(targetView: Any) {
this.targetView =
when (targetView) {
is Activity -> {
isActivity = true
targetView.window?.decorView as ViewGroup
}
is Fragment -> targetView.requireActivity().window?.decorView as ViewGroup
is ViewGroup -> targetView
else -> null
}
}

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