A reactive, declarative, lifecycle aware, testable and reusable way of using UI components on Android using Redux.
Fragment is not your view
dependencies {
// Netflix's ReComponents 0.0.1 Beta
api(name:'recomponents-0.0.1', ext:'aar')
}
private val store = StoreImpl(
reducer = ::appReducer,
initialState = AppState(),
middleware = listOf(::appMiddleware)
)
class YourActivity : AppCompatActivity() {
private val uiComponentManager by lazy {
ViewModelProviders.of(this,
object : ViewModelProvider.Factory {
@Suppress("UNCHECKED_CAST")
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
return UIComponentManager(store) as T
}
}
)[UIComponentManager::class.java]
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.linearlayout_main)
initComponents(findViewById(R.id.root))
}
private fun initComponents(container: ViewGroup) {
with(uiComponentManager) {
subscribe(YourComponent(container)) {
YourComponentState(
...
)
}
...
}
}
override fun onDestroy() {
super.onDestroy()
uiComponentManager.store.unsubscribeAll()
}
data class YourComponentState(
...
)
class YourComponent(
container: ViewGroup
) : UIComponent<YourComponentState>() {
override fun render(state: MyComponentState) {}
}
Netflix’s Android Componentization Architecture V1 - Droidcon NYC 2018 Talk
Netflix’s Android Componentization Architecture V1 - Droidcon SF 2018 Talk