wix / react-native-navigation

A complete native navigation solution for React Native
https://wix.github.io/react-native-navigation/
MIT License
13.04k stars 2.67k forks source link

[V3] TopTabs - some hierachies don't work anymore #5375

Closed ghost closed 5 years ago

ghost commented 5 years ago

Issue Description

Navigation hierachies which used to work in V2 do not work anymore.

Steps to Reproduce / Code Snippets / Screenshots

For example the following code works in V2 but not anymore in V3:

Navigation.setRoot({
        root: {
            topTabs: {
                children: [{
                    component: {
                        name: "AppScreen",
                    }
                },
                {
                    component: {
                        name: "AppScreen",
                    }
                }],
            },
        }
    });

it throws the following error:

2019-08-12 11:51:34.953 6378-6378/com.test E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.test, PID: 6378
    java.lang.ClassCastException: androidx.viewpager.widget.ViewPager$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams
        at com.reactnativenavigation.presentation.ComponentPresenterBase.applyTopInsets(ComponentPresenterBase.java:9)
        at com.reactnativenavigation.viewcontrollers.ComponentViewController.applyTopInset(ComponentViewController.java:95)
        at com.reactnativenavigation.viewcontrollers.-$$Lambda$wlwFhgHcAClBnwsp5rN0pxte4i4.on(Unknown Source:2)
        at com.reactnativenavigation.utils.CollectionUtils.forEach(CollectionUtils.java:93)
        at com.reactnativenavigation.utils.CollectionUtils.forEach(CollectionUtils.java:76)
        at com.reactnativenavigation.viewcontrollers.ParentController.applyTopInset(ParentController.java:165)
        at com.reactnativenavigation.viewcontrollers.-$$Lambda$wlwFhgHcAClBnwsp5rN0pxte4i4.on(Unknown Source:2)
        at com.reactnativenavigation.utils.CollectionUtils.forEach(CollectionUtils.java:93)
        at com.reactnativenavigation.utils.CollectionUtils.forEach(CollectionUtils.java:76)
        at com.reactnativenavigation.viewcontrollers.ParentController.applyTopInset(ParentController.java:165)
        at com.reactnativenavigation.viewcontrollers.-$$Lambda$vVglzgYrWmnbpKcV_M9VjZiqrVQ.run(Unknown Source:2)
        at com.reactnativenavigation.utils.ObjectUtils.perform(ObjectUtils.java:10)
        at com.reactnativenavigation.viewcontrollers.ViewController.onMeasureChild(ViewController.java:330)
        at com.reactnativenavigation.views.BehaviourDelegate.onMeasureChild(BehaviourDelegate.java:22)
        at com.reactnativenavigation.views.BehaviourDelegate.onMeasureChild(BehaviourDelegate.java:7)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:813)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1535)
        at android.widget.LinearLayout.measureVertical(LinearLayout.java:825)
        at android.widget.LinearLayout.onMeasure(LinearLayout.java:704)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6749)
        at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
        at com.android.internal.policy.DecorView.onMeasure(DecorView.java:716)
        at android.view.View.measure(View.java:23169)
        at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2718)
        at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1572)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1855)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1460)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:7183)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:949)
        at android.view.Choreographer.doCallbacks(Choreographer.java:761)
        at android.view.Choreographer.doFrame(Choreographer.java:696)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:935)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:193)
2019-08-12 11:51:34.954 6378-6378/com.test E/AndroidRuntime:     at android.app.ActivityThread.main(ActivityThread.java:6669)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
2019-08-12 11:51:35.016 6378-6378/com.test I/Process: Sending signal. PID: 6378 SIG: 9

i dont know much about android development so i can't find a solutoin but i think it have to do with the androidx portion because the error

androidx.viewpager.widget.ViewPager$LayoutParams cannot be cast to android.view.ViewGroup$MarginLayoutParams 

i hope there is a quick fix for it.

btw. the following works:

Navigation.setRoot({
            root: {
                topTabs: {
                    children: [{
                        stack: {
                            children: [{
                                component: {
                                    name: "AppScreen",
                                }
                            }]
                        }
                    },
                    {
                        stack: {
                            children: [{
                                component: {
                                    name: "AppScreen",
                                }
                            }]
                        }
                    }],
                },
            }
        });

Environment

isuhar commented 5 years ago

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to androidx.coordinatorlayout.widget.CoordinatorLayout$LayoutParams

+1 with bottomTabs

guyca commented 5 years ago

V3 assumes layouts are CoordinatorLayouts, we need to change this to extend CoordinatorLayout and add the ViewPager as a child of that layout.

@Damar95 Can you please take this?

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you believe the issue is still relevant, please test on the latest Detox and report back. Thank you for your contributions.

stale[bot] commented 5 years ago

The issue has been closed for inactivity.

crocodile commented 5 years ago

This is still an issue on 3.2.0 and React 0.61.2 java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to androidx.coordinatorlayout.widget.CoordinatorLayout$LayoutParams

rat-moonshine commented 4 years ago

Any update on this? The topTabs still very broken in V3. I almost have no idea how to move with my application now. Please, don't close this issue as stale.

hoorsa commented 1 month ago

+1 topTapOptions java.lang.NullPointerException: Attempt to invoke virtual method 'int android.view.ViewGroup.getChildCount()' on a null object reference 09-20 11:57:21.621 23520 23520 E AndroidRuntime: at com.reactnativenavigation.utils.ViewUtils.findChildByClass(ViewUtils.java:20) 09-20 11:57:21.621 23520 23520 E AndroidRuntime: at com.reactnativenavigation.views.toptabs.TopTabsStyleHelper.applyOnTabTitle(TopTabsStyleHelper.java:49) 09-20 11:57:21.621 23520 23520 E AndroidRuntime: at com.reactnativenavigation.views.toptabs.TopTabsStyleHelper.setFontFamily(TopTabsStyleHelper.java:45) 09-20 11:57:21.621 23520 23520 E AndroidRuntime: at com.reactnativenavigation.views.toptabs.TopTabs.setFontFamily(TopTabs.java:23) 09-20 11:57:21.621 23520 23520 E AndroidRuntime: at com.reactnativenavigation.views.stack.topbar.TopBar.setTopTabFontFamily(TopBar.java:219)