airbnb / mavericks

Mavericks: Android on Autopilot
https://airbnb.io/mavericks/
Apache License 2.0
5.83k stars 500 forks source link

Google maps fragment in epoxy view #109

Closed jQrgen closed 6 years ago

jQrgen commented 6 years ago

I'm currently exploring the new MvRx stack from Airbnb

Rigth now i am adding a google maps fragment successfully to a BaseMvRxFragment in a BottomNavigationView.

The problem is that the 2. time i navigate to the MapFragment my app crashes and i get the following error message:

    E/AndroidRuntime: FATAL EXCEPTION: main
        Process: getflareapp.com.s2s, PID: 19184
        android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment
        Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
        Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f080093, tag null, or parent id 0xffffffff with another fragment for com.google.android.gms.maps.SupportMapFragment
            at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:3752)
            at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
            at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:405)
            at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:387)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:780)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:730)
            at android.view.LayoutInflater.rInflate(LayoutInflater.java:863)
            at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:824)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
            at android.view.View.inflate(View.java:23239)
            at getflareapp.com.s2s.views.MapView.<init>(MapView.kt:19)
            at getflareapp.com.s2s.views.MapView.<init>(MapView.kt:14)
            at getflareapp.com.s2s.views.MapView.<init>(Unknown Source:6)
            at getflareapp.com.s2s.views.MapViewModel_.buildView(MapViewModel_.java:42)
            at getflareapp.com.s2s.views.MapViewModel_.buildView(MapViewModel_.java:22)

MapFragment.kt

    /**
     * A simple [BaseFragment] subclass.
     *
     */
    class MapFragment : BaseFragment() {

        private val mViewModel: ChatViewModel by fragmentViewModel()

        override fun epoxyController() = simpleController(mViewModel) {state ->

            mapView{
                id("map")
            }
        }
    }

MapView.kt

 @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 {
            // TODO: Fix crash on second view.
            inflate(context, R.layout.view_map, this)
        }
    }

view_map.xml

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

        <fragment xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:tools="http://schemas.android.com/tools"
            android:id="@+id/map2"
            android:name="getflareapp.com.s2s.ui.map.MapFragment"
            class="com.google.android.gms.maps.SupportMapFragment"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".ui.MainActivity" />

    </FrameLayout>

Thanks for any help! <3

jQrgen commented 6 years ago

Moved to epoxy repo: https://github.com/airbnb/epoxy/issues/558