airbnb / mavericks

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

Does mavericks-mocking support Jetpack compose? #602

Open sanginovs opened 2 years ago

sanginovs commented 2 years ago

Hi @elihart First of all, thanks a lot for open sourcing these mocking libraries. I am trying to setup mavericks-mocking and mavericks-launcher in our codebase and was wondering if mavericks-mocking support composable views?

elihart commented 2 years ago

there is no compose specific support in the mocking. if you have a mocked fragment that uses composables within its view I think it should work fine, but overall it only works with Fragments still

sanginovs commented 2 years ago

@elihart any plans/timeline to add compose specific support (embed in a single activity) in the near future?

I couldn't get it to work on my Activity which uses composable. Seems like the mocking library won't work if i don't have any fragments in my activity.

for reference, here's my setup. It's a single activity which uses Compose:

class MyActivty: MockableMavericksView {
       private val viewModel: XYZViewModel by activityViewModel()
       ...
       override fun provideMocks() = mockSingleViewModel(
          viewModelReference = MyActivity::viewModel,
          defaultState = MyState(...),
          defaultArgs = null) { }
        ...

       @ExperimentalComposeUiApi
       @ExperimentalFoundationApi
        override fun onCreate(savedInstanceState: Bundle?) { 
           registerMockPrinter()

           setContent {
              MyComposableView()
          }

       }     
}
elihart commented 2 years ago

This is related to https://github.com/airbnb/mavericks/issues/544 - right now the MavericksView interface is required.

In the coming months we will be working on compose specific support, but not timeline to promise for now

sanginovs commented 2 years ago

thanks again @elihart. looking forward to it