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

Google maps and BottomNavigationView #100

Closed
jQrgen opened this issue Sep 27, 2018 · 1 comment
Closed

Google maps and BottomNavigationView #100

jQrgen opened this issue Sep 27, 2018 · 1 comment

Comments

@jQrgen
Copy link

jQrgen commented Sep 27, 2018

Hello

I'm trying to setup google maps inside of BottomNavigationView tab using MvRx.

I have to questions:

  1. What is the best pracice for setting up BottomNavigationView in MvRx?
  2. Using the code below I managed to load the map once but the second time i open the tab i get the following error. Therefore i am wondering what the recommended way to setup google maps in a BottomNavigationView fragment using MvRx is?
Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f080089, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment

My fragment looks like this:

class MapFragment : BaseFragment() {

    private val mViewModel: ChatViewModel by fragmentViewModel()

    override fun epoxyController() = simpleController(mViewModel) {state ->
        mapView{
            id("map")
        }
    }
}

And view:

@ModelView(autoLayout = ModelView.Size.MATCH_WIDTH_MATCH_HEIGHT)
class MapView @JvmOverloads constructor(
        context: Context,
        attrs: AttributeSet? = null,
        defStyleAttr: Int = 0
) : FrameLayout(context, attrs, defStyleAttr) {

    init {
        inflate(context, R.layout.fragment_map, this)
    }

}

Map fragment (Crashes on second inflate)

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</FrameLayout>

main_activity

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


        <fragment
            android:id="@+id/my_nav_host_fragment"
            android:name="androidx.navigation.fragment.NavHostFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:defaultNavHost="true"
            app:layout_behavior="@string/appbar_scrolling_view_behavior"
            app:navGraph="@navigation/nav_graph" />

        <android.support.design.widget.BottomNavigationView
            android:id="@+id/bottom_navigation"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/white"
            app:itemTextColor="@color/bottom_navigation_text"
            app:layout_behavior="android.support.design.behavior.HideBottomViewOnScrollBehavior"
            app:menu="@menu/bottom_navigation_main" />


</android.support.design.widget.CoordinatorLayout>

MainActivity

class MainActivity: BaseMvRxActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        setupNavigation()
    }

    private fun setupNavigation() {
        val navController = findNavController(R.id.my_nav_host_fragment)
        bottom_navigation.setupWithNavController(navController)
    }

    override fun onSupportNavigateUp() =
            findNavController(R.id.my_nav_host_fragment).navigateUp()

}
@jQrgen
Copy link
Author

jQrgen commented Sep 28, 2018

Moved to stackoverflow where it belongs: https://stackoverflow.com/questions/52555009/google-maps-and-bottomnavigationview

@jQrgen jQrgen closed this as completed Sep 28, 2018
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

1 participant