FinTecSystems / xs2a-android

[Client] Native Android SDK for Tink Germany XS2A API.
https://tink.com/de/fts
Other
6 stars 4 forks source link

UnsupportedOperationException: Cannot add views to ComposeView; only Compose content is supported #20

Open Emeshey opened 11 months ago

Emeshey commented 11 months ago

Hello @maik-mursall !

TLDR: I am having a crash when I tap on the "Next" button on the first screen of the sdk, while leaving the Bank name field empty, the second time I enter the screen. I'm using 5.1.4 version of the sdk.

Full stacktrace:

java.lang.UnsupportedOperationException: Cannot add views to ComposeView; only Compose content is supported
at androidx.compose.ui.platform.AbstractComposeView.checkAddView(ComposeView.android.kt:200)
at androidx.compose.ui.platform.AbstractComposeView.addView(ComposeView.android.kt:344)
at android.transition.TransitionUtils.createViewBitmap(TransitionUtils.java:192)
at android.transition.TransitionUtils.copyViewImage(TransitionUtils.java:103)
at android.transition.Visibility.onDisappear(Visibility.java:420)
at android.transition.Visibility.createAnimator(Visibility.java:255)
at android.transition.Transition.createAnimators(Transition.java:734)
at android.transition.TransitionSet.createAnimators(TransitionSet.java:444)
at android.transition.TransitionSet.createAnimators(TransitionSet.java:444)
at android.transition.Transition.playTransition(Transition.java:1778)
at android.transition.TransitionManager$MultiListener.onPreDraw(TransitionManager.java:328)
at android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:1121)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:4442)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:3116)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:10885)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1301)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1309)
at android.view.Choreographer.doCallbacks(Choreographer.java:923)
at android.view.Choreographer.doFrame(Choreographer.java:852)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1283)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8757)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

Steps to reproduce:

  1. Open the fintec sdk the first time, leave the Bank name field empty and tap "Next".
  2. Open the fintec sdk the second time (in the same sessions), leave the Bank name field empty and tap "Next".
  3. Repeat previous step 5 times, if needed.
  4. See that the app crashes.

My problem is that I don't use compose in my app at all, and still get this crash. I reproduced it on:

What I've tried so far:

I saw online that setting isTransitionGroup = true on the ComposeView helps, but I do not have access to it.

maik-mursall commented 11 months ago

Hi @Emeshey, I will take a look at it :)

maik-mursall commented 11 months ago

I cannot reproduce this crash using your steps 🤔

What do you do with the Fragment between steps 1/2? I've tried:

All three scenarios resulted in no crash and normal behaviour...

Did you do something differently or could you share with me a minimal repository, where this Issue exists? :)

Emeshey commented 11 months ago

Hello :) I have the following structure:

<FrameLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <FrameLayout
                android:id="@+id/fintec_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:visibility="@{viewModel.fintecVisibility}" />

            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:visibility="@{!viewModel.fintecVisibility}">

               <Button...../>

              </androidx.constraintlayout.widget.ConstraintLayout>

</FrameLayout>

When I press the button, the fintec flow will start:

requireActivity().supportFragmentManager.beginTransaction()
                        .let { fragmentTransaction ->
                            fragmentTransaction.add(
                                R.id.fintec_layout,
                                prepareFintecFragment(it.token)
                            )
                            fragmentTransaction.commit()
                        }

The prepare method:

private fun prepareFintecFragment(token: String): XS2AWizardFragment {
        val theme = XS2ATheme(
            tintColor = XS2AColor(requireContext().getColor(R.color.colorPrimary)),
            submitButtonStyle = ButtonStyle(
                backgroundColor = XS2AColor(requireContext().getColor(R.color.colorPrimary)),
                textColor = XS2AColor(requireContext().getColor(R.color.white))
            )
        )
        return XS2AWizardFragment(
            sessionKey = token,
            theme = theme
        )
    }

If I get an error (which is not the testmode_error), I change the fintecVisibility to false.

maik-mursall commented 11 months ago

With your example I'm still not able to reproduce this 🤔 I tested in on a API-Level 23 and 33 Emulator.

Does this still occur when you manually set the visibility instead of using a data binding?

Emeshey commented 11 months ago

Hm, this seems to solve the problem. So note for other devs in the future: don't use data binding for this one :) Thank you for your fast answers.

maik-mursall commented 11 months ago

Glad to hear you found the cause of this Issue :)

I will try to get data binding to work for my test environment, so I can maybe find a fix on our end, so projects with data binding enabled can use the sdk without any workarounds :)

I will keep this Issue open for the further investigation of this :)

FriedrichSchlee commented 2 weeks ago

@maik-mursall Is this still needed? or can we close this issue?