This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultLandingComponent( | |
componentContext: ComponentContext | |
) : LandingComponent, ComponentContext by componentContext { | |
private val landingNavigation = StackNavigation<LandingConfig>() | |
override val routerState: Value<ChildStack<*, LandingComponent.LandingChild>> = | |
childStack( | |
source = landingNavigation, | |
serializer = LandingConfig.serializer(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface LandingComponent { | |
val routerState: Value<ChildStack<*, LandingChild>> | |
sealed class LandingChild { | |
data class SplashChild(val component: SplashComponent) : LandingChild() | |
data class OnboardingChild(val component: OnboardingComponent) : LandingChild() | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : ComponentActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
val rootComponent = DefaultRootComponent(defaultComponentContext()) | |
setContent { | |
AppTheme { | |
Surface( | |
modifier = Modifier.fillMaxSize(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun RootContent(rootComponent: RootComponent) { | |
val routerState by rootComponent.routerState.subscribeAsState() | |
when (val child = routerState.active.instance) { | |
is LandingRoot -> LandingContent(landingComponent = child.landingComponent) | |
is AuthRoot -> AuthContent(authComponent = child.authComponent) | |
is MainRoot -> MainContent(mainComponent = child.mainComponent) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DefaultRootComponent( | |
componentContext: ComponentContext | |
) : RootComponent, ComponentContext by componentContext { | |
private val rootNavigation = StackNavigation<RootConfig>() | |
override val routerState: Value<ChildStack<*, RootChild>> = | |
childStack( | |
source = rootNavigation, | |
serializer = RootConfig.serializer(), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface RootComponent { | |
val routerState: Value<ChildStack<*, RootChild>> | |
fun navigateToAuth() | |
fun navigateToHome() | |
//This will be used to decide between navigations | |
sealed class RootChild { | |
data class LandingRoot(val landingComponent: LandingComponent): RootChild() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class ProductVariant(val id: String, val productName: String, val type: String) | |
sealed class ProductVariantUIState { | |
data class ProductVariantStateSuccess(val items: List<ProductVariant>): ProductVariantUIState() | |
data class ProductVariantStateFailure(val error: String): ProductVariantUIState() | |
object Loading: ProductVariantUIState() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductVariantViewModel: ViewModel() { | |
private var _variantsUiState = MutableStateFlow<ProductVariantUIState>(ProductVariantUIState.Loading) | |
val variantsUiState = _variantsUiState.asStateFlow() | |
private var _selectedVariant = MutableSharedFlow<ProductVariant>() | |
val selectedVariant = _selectedVariant.asSharedFlow() | |
fun loadVariantsForProduct(id: String) { | |
viewModelScope.launch { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ProductVariantBottomSheet: BottomSheetDialogFragment() { | |
private val viewModel: ProductVariantViewModel by sharedViewModel() | |
private val args: ProductVariantBottomSheetArgs by navArgs() | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
setupUI() | |
observeViewModel() | |
viewModel.loadVariantsForProduct(args.productId) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HomeFragment : Fragment() { | |
private val userViewModel: UserViewModel by sharedViewModel() //using koin | |
// OR | |
// private val userViewModel: UserViewModel by activityViewModels() //using androidx | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
userViewModel.fetchUserProfile() | |
observeViewModel() |
NewerOlder