Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[카카오T~픽커앱 개발기] state관리 Mavericks 에서 circuit까지

kakao
November 01, 2024

[카카오T~픽커앱 개발기] state관리 Mavericks 에서 circuit까지

"유명한 Airbnb MVI프레임워크과 슬랙사의 Circuit을 카카오T와 픽커앱에 접목시킨 재미난 개발기 presentation layer에서 겪었던 상태 관리 프레임워크 적용기"

발표자 : roy.tk
카카오T픽커 android 공통개발을 담당하고 있는 roy입니다.

kakao

November 01, 2024
Tweet

More Decks by kakao

Other Decks in Programming

Transcript

  1. .BWFSJDLT੄੢੼  .7*  TJOHMF - TUBUF 6OJEJSFDUJPOBM - %BUB

    - 'MPX  TUBUFী؀ೠઑഥࣻ੿ਸױੌUISFBE۽ъઁ  TUBUFী؀ೠଵઑܳਤೠFYUFOTJPOӝמઁҕ  ڪযդޙࢲച
  2. .BWFSJDLT੄੢੼  .7*  TJOHMF - TUBUF 6OJEJSFDUJPOBM - %BUB

    - 'MPX  TUBUFী؀ೠઑഥࣻ੿ਸױੌUISFBE۽ъઁ  TUBUFী؀ೠଵઑܳਤೠFYUFOTJPOӝמઁҕ  ڪযդޙࢲച
  3. ֙.BWFSJDLT੄ޙઁ੼  .7*  TJOHMF - TUBUF  TUBUFী؀ೠઑഥࣻ੿ਸױੌUISFBE۽ъઁ 

    TUBUFী؀ೠଵઑܳਤೠFYUFOTJPOӝמઁҕ  ڪযդޙࢲച DPSPVUJOFਵ۽औѱоמ DPNQPTFܳ੉ਊೞݶऔѱоמ ࠛ೙ਃೞѱࠂ੟ೠ೐ۨ੐ਕ௼
  4. $JSDVJU੄ౠ૚  .7*  TJOHMF - TUBUF 6OJEJSFDUJPOBM - %BUB

    - 'MPX  DPNQPTF - SVOUJNFӝ߈੄TUBUFҙܻ  TDSFFOױਤ੄OBWJHBUJPOӝמ૑ਗ
  5. 1SFTFOUFS @Composable fun CounterPresenter(screen: CounterScreen, navigator: Navigator): CounterScreen.State { var

    count by remember(screen) { mutableStateOf(screen.initialCount) } return CounterScreen.State( count = count, eventSink = { event -> when (event) { is CounterScreen.Event.GoTo -> navigator.goTo(event.target) is CounterScreen.Event.Increment -> count++ is CounterScreen.Event.Decrement -> count-- } }, ) }
  6. 1SFTFOUFS @Composable fun CounterPresenter(screen: CounterScreen, navigator: Navigator): CounterScreen.State { var

    count by remember(screen) { mutableStateOf(screen.initialCount) } return CounterScreen.State( count = count, eventSink = { event -> when (event) { is CounterScreen.Event.GoTo -> navigator.goTo(event.target) is CounterScreen.Event.Increment -> count++ is CounterScreen.Event.Decrement -> count-- } }, ) }
  7. 1SFTFOUFS @Composable fun CounterPresenter(screen: CounterScreen, navigator: Navigator): CounterScreen.State { var

    count by remember(screen) { mutableStateOf(screen.initialCount) } return CounterScreen.State( count = count, eventSink = { event -> when (event) { is CounterScreen.Event.GoTo -> navigator.goTo(event.target) is CounterScreen.Event.Increment -> count++ is CounterScreen.Event.Decrement -> count-- } }, ) }
  8. 1SFTFOUFS @Composable fun CounterPresenter(screen: CounterScreen, navigator: Navigator): CounterScreen.State { var

    count by remember(screen) { mutableStateOf(screen.initialCount) } return CounterScreen.State( count = count, eventSink = { event -> when (event) { is CounterScreen.Event.GoTo -> navigator.goTo(event.target) is CounterScreen.Event.Increment -> count++ is CounterScreen.Event.Decrement -> count-- } }, ) }
  9. 1SFTFOUFS @Composable fun CounterPresenter(screen: CounterScreen, navigator: Navigator): CounterScreen.State { var

    count by remember(screen) { mutableStateOf(screen.initialCount) } return CounterScreen.State( count = count, eventSink = { event -> when (event) { is CounterScreen.Event.GoTo -> navigator.goTo(event.target) is CounterScreen.Event.Increment -> count++ is CounterScreen.Event.Decrement -> count-- } }, ) }
  10. 6* @Composable fun CounterUi(state: CounterScreen.State, modifier: Modifier = Modifier) {

    Column(modifier = modifier) { Text(text = "Count: ${state.count}") Button(onClick = { state.eventSink(CounterScreen.Event.Increment) }) { Text("+") } Button(onClick = { state.eventSink(CounterScreen.Event.Decrement) }) { Text("-") } } }
  11. 6* @Composable fun CounterUi(state: CounterScreen.State, modifier: Modifier = Modifier) {

    Column(modifier = modifier) { Text(text = "Count: ${state.count}") Button(onClick = { state.eventSink(CounterScreen.Event.Increment) }) { Text("+") } Button(onClick = { state.eventSink(CounterScreen.Event.Decrement) }) { Text("-") } } }
  12. -JOLJOH class CounterActivity : AppCompatActivity() { private val circuit: Circuit

    = Circuit.Builder() .addPresenter<CounterScreen, CounterScreen.State> { screen, navigator, _ -> presenterOf { CounterPresenter(screen, navigator) } } .addUi<CounterScreen, CounterScreen.State> { state, modifier -> CounterUi(state, modifier) } .build() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { CircuitCompositionLocals(circuit) { CircuitContent(CounterScreen) } } } }
  13. -JOLJOH class CounterActivity : AppCompatActivity() { private val circuit: Circuit

    = Circuit.Builder() .addPresenter<CounterScreen, CounterScreen.State> { screen, navigator, _ -> presenterOf { CounterPresenter(screen, navigator) } } .addUi<CounterScreen, CounterScreen.State> { state, modifier -> CounterUi(state, modifier) } .build() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { CircuitCompositionLocals(circuit) { CircuitContent(CounterScreen) } } } }
  14. -JOLJOH class CounterActivity : AppCompatActivity() { private val circuit: Circuit

    = Circuit.Builder() .addPresenter<CounterScreen, CounterScreen.State> { screen, navigator, _ -> presenterOf { CounterPresenter(screen, navigator) } } .addUi<CounterScreen, CounterScreen.State> { state, modifier -> CounterUi(state, modifier) } .build() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { CircuitCompositionLocals(circuit) { CircuitContent(CounterScreen) } } } }
  15. -JOLJOH class CounterActivity : AppCompatActivity() { private val circuit: Circuit

    = Circuit.Builder() .addPresenter<CounterScreen, CounterScreen.State> { screen, navigator, _ -> presenterOf { CounterPresenter(screen, navigator) } } .addUi<CounterScreen, CounterScreen.State> { state, modifier -> CounterUi(state, modifier) } .build() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContent { CircuitCompositionLocals(circuit) { CircuitContent(CounterScreen) } } } }
  16. ੗ਬ۽਍#BDL4UBDLஶ౟܀  #BDL4UBDLDPO fi HVSBUJPO߸҃ীبਬ૑غח4DSFFO੄झఖਸ੷੢  /BWJHBUPS#BDL4UBDLী؀ೠױࣽೠJOUFSGBDFܳઁҕ  /BWJHBCMF$JSDVJU$POUFOU#BDL4UBDL੄UPQTDSFFOਸ֢୹ setContent

    { val backStack = rememberSaveableBackStack(root = HomeScreen) val navigator = rememberCircuitNavigator(backStack) NavigableCircuitContent(navigator, backStack) }
  17. ੗ਬ۽਍#BDL4UBDLஶ౟܀  #BDL4UBDLDPO fi HVSBUJPO߸҃ীبਬ૑غח4DSFFO੄झఖਸ੷੢  /BWJHBUPS#BDL4UBDLী؀ೠױࣽೠJOUFSGBDFܳઁҕ  /BWJHBCMF$JSDVJU$POUFOU#BDL4UBDL੄UPQTDSFFOਸ֢୹ setContent

    { val backStack = rememberSaveableBackStack(root = HomeScreen) val navigator = rememberCircuitNavigator(backStack) NavigableCircuitContent(navigator, backStack) }
  18. ੗ਬ۽਍#BDL4UBDLஶ౟܀  #BDL4UBDLDPO fi HVSBUJPO߸҃ীبਬ૑غח4DSFFO੄झఖਸ੷੢  /BWJHBUPS#BDL4UBDLী؀ೠױࣽೠJOUFSGBDFܳઁҕ  /BWJHBCMF$JSDVJU$POUFOU#BDL4UBDL੄UPQTDSFFOਸ֢୹ setContent

    { val backStack = rememberSaveableBackStack(root = HomeScreen) val navigator = rememberCircuitNavigator(backStack) NavigableCircuitContent(navigator, backStack) }
  19. ੗ਬ۽਍#BDL4UBDLஶ౟܀ @Composable fun HomePresenter(..., navigator: Navigator): HomeScreen.State { ... return

    HomeScreen.State(...) { event -> when (event) { is HomeScreen.Event.ShowAddFavorites -> navigator.goTo(AddFavoritesScreen(externalId = event.id) ... } } }