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

MavericksLauncherMockActivity crashes if there's no App.Theme or if fragments are Hilt fragments #671

Open
kenyee opened this issue Feb 24, 2023 · 1 comment

Comments

@kenyee
Copy link
Contributor

kenyee commented Feb 24, 2023

From testing w/ a small Compose test app where there's no App theme, this activity can crash with this error:

UnsupportedOperationException: Failed to resolve attribute at index 1: TypedValue{t=0x2/d=0x7f030003 a=-1}, theme={InheritanceMap=[id=0x103013fandroid:style/Theme.DeviceDefault.Light.DarkActionBar, 

Fix is to add an app theme but probably should be documented.

Also, when launching a Hilt Fragment MockableMavericksView from MavericksLauncherMockActivity, this happens:

java.lang.IllegalStateException: Hilt Fragments must be attached to an @AndroidEntryPoint Activity. Found: class com.airbnb.mvrx.launcher.MavericksLauncherMockActivity

Wrapping the MavericksLauncherMockActivity like this had the same error:

@AndroidEntryPoint
class HiltMavericksLauncherMockActivity : MavericksLauncherActivity() {

    companion object {
        private inline fun <reified T> Context.buildIntent(initializer: Intent.() -> Unit = {}): Intent {
            return Intent(this, T::class.java).apply(initializer)
        }

        fun show(context: Context) {
            context.startActivity(context.buildIntent<HiltMavericksLauncherMockActivity>())
        }
    }
}

even when launching with "HiltMavericksLauncherMockActivity.show(this)"

@kenyee
Copy link
Contributor Author

kenyee commented Feb 28, 2023

This looks like just a docs issue...doing this works fine and probably should be part of the mavericks-hilt module?

@AndroidEntryPoint
class HiltMavericksLauncherMockActivity : MavericksBaseLauncherActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        if (savedInstanceState == null) {
            MavericksLauncherMockActivity.showNextMockFromActivity(
                activity = this,
                showView = { mavericksView ->
                    // Use whatever custom code you want to show your Mavericks View
                    setFragment(mavericksView as Fragment, commitNow = true)
                },
            )
        }
    }
}

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