-
Notifications
You must be signed in to change notification settings - Fork 13
feat: Implement onboarding screen UI #70
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
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4907d2b
feat: add NoRippleClick util
MostafaMohamed2002 36b9cc8
feat: add language selection strings
MostafaMohamed2002 43a0039
feat: add Onboarding and arrow-down drawables
MostafaMohamed2002 479c955
feat: create OnboardingScreenState
MostafaMohamed2002 6df252b
feat: add OnboardingScreenListener interface
MostafaMohamed2002 6ed6a0a
feat: add onboarding screen effects
MostafaMohamed2002 97672c4
feat: create OnBoardingViewModel
MostafaMohamed2002 bc1de17
feat: add onBoardingViewModel to viewModelModule
MostafaMohamed2002 95e8def
feat: implement onboarding screen UI and logic
MostafaMohamed2002 f20a3a4
Merge branch 'develop' into feature/on-boarding
MostafaMohamed2002 7e2e58b
feat: internationalize language display name in onboarding screen
MostafaMohamed2002 b1b2f48
Refactor: OnBoardingViewModel extends BaseViewModel
MostafaMohamed2002 474fd07
refactor : use callbacks instead of passing navController
MostafaMohamed2002 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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
This file contains hidden or 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
2 changes: 2 additions & 0 deletions
2
composeApp/src/commonMain/kotlin/com/cairosquad/evolvefit/di/viewModelModule.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| package com.cairosquad.evolvefit.di | ||
|
|
||
| import com.cairosquad.evolvefit.ui.screen.onBoarding.OnBoardingViewModel | ||
| import com.cairosquad.evolvefit.viewmodel.register.RegisterViewModel | ||
| import org.koin.core.module.dsl.viewModelOf | ||
| import org.koin.dsl.module | ||
|
|
||
| val viewModelModule = module { | ||
| viewModelOf(::RegisterViewModel) | ||
| viewModelOf(::OnBoardingViewModel) | ||
| } |
37 changes: 37 additions & 0 deletions
37
...rc/commonMain/kotlin/com/cairosquad/evolvefit/ui/screen/onBoarding/OnBoardingViewModel.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| package com.cairosquad.evolvefit.ui.screen.onBoarding | ||
|
|
||
| import com.cairosquad.evolvefit.viewmodel.base.BaseViewModel | ||
|
|
||
| class OnBoardingViewModel : | ||
| BaseViewModel<OnboardingScreenState, OnboardingScreenEffect>(OnboardingScreenState()), | ||
| OnboardingScreenListener { | ||
|
|
||
| override fun onChangeLanguage(language: OnboardingScreenState.Language) { | ||
| updateState { | ||
| it.copy(bottomSheetSelectedLanguage = language) | ||
| } | ||
| } | ||
|
|
||
| override fun onConfirmClicked() { | ||
| updateState { | ||
| it.copy( | ||
| selectedLanguage = it.bottomSheetSelectedLanguage, | ||
| isBottomSheetOpen = false | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| override fun toggleBottomSheet(isOpen: Boolean) { | ||
| updateState { | ||
| it.copy(isBottomSheetOpen = isOpen) | ||
| } | ||
| } | ||
|
|
||
| override fun onSignUpClicked() { | ||
| sendEffect(OnboardingScreenEffect.NavigateToRegister) | ||
| } | ||
|
|
||
| override fun onLoginClicked() { | ||
| sendEffect(OnboardingScreenEffect.NavigateToLogin) | ||
| } | ||
| } |
221 changes: 202 additions & 19 deletions
221
...p/src/commonMain/kotlin/com/cairosquad/evolvefit/ui/screen/onBoarding/OnboardingScreen.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,39 +1,222 @@ | ||
| package com.cairosquad.evolvefit.ui.screen.onBoarding | ||
|
|
||
| import androidx.compose.foundation.Image | ||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.Box | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.material3.Button | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.height | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.size | ||
| import androidx.compose.foundation.layout.statusBarsPadding | ||
| import androidx.compose.foundation.layout.wrapContentWidth | ||
| import androidx.compose.foundation.shape.RoundedCornerShape | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.ui.Alignment | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.draw.clip | ||
| import androidx.compose.ui.layout.ContentScale | ||
| import androidx.compose.ui.unit.dp | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import androidx.navigation.NavController | ||
| import com.cairosquad.evolvefit.design_system.component.BottomSheet | ||
| import com.cairosquad.evolvefit.design_system.component.CheckboxItem | ||
| import com.cairosquad.evolvefit.design_system.component.CheckboxStyle | ||
| import com.cairosquad.evolvefit.design_system.component.PrimaryButton | ||
| import com.cairosquad.evolvefit.design_system.theme.AppTheme | ||
| import com.cairosquad.evolvefit.design_system.theme.Theme | ||
| import com.cairosquad.evolvefit.ui.navigation.LoginRoute | ||
| import com.cairosquad.evolvefit.ui.navigation.RegisterRoute | ||
| import com.cairosquad.evolvefit.ui.util.ObserveAsEffect | ||
| import com.cairosquad.evolvefit.ui.util.noRippleClickable | ||
| import org.jetbrains.compose.ui.tooling.preview.Preview | ||
| import evolvefit.composeapp.generated.resources.Onboarding | ||
| import evolvefit.composeapp.generated.resources.Res | ||
| import evolvefit.composeapp.generated.resources.arrow_down | ||
| import evolvefit.composeapp.generated.resources.choose_language | ||
| import evolvefit.composeapp.generated.resources.do_you_have_an_account | ||
| import evolvefit.composeapp.generated.resources.language_selection_description | ||
| import evolvefit.composeapp.generated.resources.login | ||
| import evolvefit.composeapp.generated.resources.ready_to_start | ||
| import org.jetbrains.compose.resources.painterResource | ||
| import org.jetbrains.compose.resources.stringResource | ||
| import org.koin.compose.viewmodel.koinViewModel | ||
|
|
||
| @Composable | ||
| fun OnboardingScreen( | ||
| navigateToLogin: () -> Unit, | ||
| navigateToRegister: () -> Unit, | ||
| viewmodel: OnBoardingViewModel = koinViewModel(), | ||
| navigateToRegister : () -> Unit, | ||
| navigateToLogin : () -> Unit, | ||
| ) { | ||
| Column( | ||
| modifier = Modifier.fillMaxSize(), | ||
| verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterVertically), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| val state by viewmodel.screenState.collectAsStateWithLifecycle() | ||
| ObserveAsEffect(viewmodel.effect) { effect -> | ||
| when (effect) { | ||
| OnboardingScreenEffect.NavigateToLogin -> { | ||
| navigateToLogin() | ||
| } | ||
| OnboardingScreenEffect.NavigateToRegister -> { | ||
| navigateToRegister() | ||
| } | ||
| } | ||
| } | ||
| OnboardingScreenContent( | ||
| state = state, | ||
| onSignupClick = viewmodel::onSignUpClicked, | ||
| onLoginClick = viewmodel::onLoginClicked, | ||
| onToggleBottomSheet = viewmodel::toggleBottomSheet, | ||
| onLanguageSelected = viewmodel::onChangeLanguage, | ||
| onConfirmClick = viewmodel::onConfirmClicked | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| fun OnboardingScreenContent( | ||
| state: OnboardingScreenState, | ||
| modifier: Modifier = Modifier, | ||
| onSignupClick: () -> Unit, | ||
| onLoginClick: () -> Unit, | ||
| onToggleBottomSheet: (isOpen: Boolean) -> Unit, | ||
| onLanguageSelected: (language: OnboardingScreenState.Language) -> Unit, | ||
| onConfirmClick: () -> Unit | ||
| ) { | ||
| Box( | ||
| modifier = modifier.fillMaxSize() | ||
| ) { | ||
| Image( | ||
| painter = painterResource(Res.drawable.Onboarding), | ||
| contentDescription = "onboarding image", | ||
| modifier = Modifier.fillMaxSize(), | ||
| contentScale = ContentScale.FillBounds | ||
| ) | ||
| Row( | ||
| modifier = Modifier.align(Alignment.TopEnd).statusBarsPadding().height(48.dp) | ||
| .wrapContentWidth() | ||
| .noRippleClickable { onToggleBottomSheet(state.isBottomSheetOpen.not()) }, | ||
| horizontalArrangement = Arrangement.End | ||
| ) { | ||
| Text( | ||
| text = stringResource(state.selectedLanguage.displayNameRes), | ||
| style = Theme.textStyle.label.mediumMedium16, | ||
| color = Theme.color.surfaces.textColor, | ||
| modifier = Modifier.padding(top = 14.5.dp, bottom = 14.5.dp, end = 8.dp) | ||
| ) | ||
| Image( | ||
| painter = painterResource(Res.drawable.arrow_down), | ||
| contentDescription = "arrow down", | ||
| modifier = Modifier.padding( | ||
| end = 16.dp, top = 14.5.dp, bottom = 14.5.dp | ||
| ).size(20.dp) | ||
| ) | ||
| } | ||
| //bottom section [ready to start - login] | ||
| Column( | ||
| modifier = Modifier.align(Alignment.BottomCenter), | ||
| horizontalAlignment = Alignment.CenterHorizontally | ||
| ) { | ||
| Box( | ||
| modifier = Modifier.padding(start = 16.dp, end = 16.dp, bottom = 24.dp) | ||
| .clip(RoundedCornerShape(24.dp)) | ||
| .height(48.dp).background( | ||
| Theme.color.brand.primary, | ||
| ).fillMaxWidth().noRippleClickable(onClick = onSignupClick), | ||
| contentAlignment = Alignment.Center | ||
| ) { | ||
| Text( | ||
| text = stringResource(Res.string.ready_to_start), | ||
| style = Theme.textStyle.body.mediumMedium14, | ||
| color = Theme.color.brand.onPrimary | ||
| ) | ||
| } | ||
|
|
||
| Text("Welcome to EvolveFit", color = Theme.color.surfaces.onSurface) | ||
| Text("Get Fit Don't Quit", color = Theme.color.surfaces.onSurface) | ||
| Row( | ||
| modifier = Modifier.padding(bottom = 24.dp).fillMaxWidth(), | ||
| horizontalArrangement = Arrangement.Center, | ||
| verticalAlignment = Alignment.CenterVertically | ||
| ) { | ||
| Text( | ||
| text = stringResource(Res.string.do_you_have_an_account), | ||
| style = Theme.textStyle.label.mediumMedium14, | ||
| color = Theme.color.surfaces.textColor, | ||
| modifier = Modifier.padding(end = 4.dp) | ||
| ) | ||
| Text( | ||
| text = stringResource(Res.string.login), | ||
| style = Theme.textStyle.label.mediumMedium16, | ||
| color = Theme.color.brand.primary, | ||
| modifier = Modifier.padding(end = 4.dp).noRippleClickable(onClick = onLoginClick) | ||
| ) | ||
|
|
||
| } | ||
|
|
||
| Button( | ||
| onClick = navigateToLogin | ||
| ){ | ||
| Text("go to Login") | ||
| } | ||
| Button( | ||
| onClick = navigateToRegister | ||
| ){ | ||
| Text("go to Register") | ||
| } | ||
|
|
||
| BottomSheet( | ||
| isVisible = state.isBottomSheetOpen, | ||
| onDismiss = { | ||
| onToggleBottomSheet(false) | ||
| }, | ||
| content = { | ||
| Column( | ||
| modifier = Modifier.padding(16.dp) | ||
| ) { | ||
| Text( | ||
| text = stringResource(Res.string.choose_language), | ||
| style = Theme.textStyle.label.mediumMedium16, | ||
| color = Theme.color.surfaces.onSurface, | ||
| modifier = Modifier.padding(bottom = 4.dp) | ||
| ) | ||
| Text( | ||
| text = stringResource(Res.string.language_selection_description), | ||
| style = Theme.textStyle.label.mediumMedium12, | ||
| color = Theme.color.surfaces.onSurfaceVariant, | ||
| modifier = Modifier.padding(bottom = 16.dp) | ||
| ) | ||
| OnboardingScreenState.Language.entries.forEach { language -> | ||
| CheckboxItem( | ||
| text = stringResource(language.displayNameRes), | ||
| isChecked = language == state.bottomSheetSelectedLanguage, | ||
| onCheckedChange = { onLanguageSelected(language) }, | ||
| style = CheckboxStyle.Tick, | ||
| modifier = modifier.padding( | ||
| bottom = 12.dp | ||
| ) | ||
| ) | ||
| } | ||
| PrimaryButton( | ||
| text = "Confirm", | ||
| onClick = { onConfirmClick() }, | ||
| modifier = Modifier.padding( | ||
| start = 16.dp, end = 16.dp, bottom = 16.dp , top = 28.dp | ||
| ) | ||
| ) | ||
| } | ||
| }, | ||
| ) | ||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| @Preview | ||
| @Composable | ||
| fun OnboardingScreenContentPreview() { | ||
| var state = OnboardingScreenState().copy(isBottomSheetOpen = true,) | ||
| AppTheme( | ||
| isDarkTheme = true | ||
| ) { | ||
| OnboardingScreenContent( | ||
| state, | ||
| onSignupClick = { }, | ||
| onLoginClick = { }, | ||
| onToggleBottomSheet = {state.isBottomSheetOpen.not()}, | ||
| onLanguageSelected = { }, | ||
| onConfirmClick = {} | ||
| ) | ||
| } | ||
|
|
||
| } |
6 changes: 6 additions & 0 deletions
6
...commonMain/kotlin/com/cairosquad/evolvefit/ui/screen/onBoarding/OnboardingScreenEffect.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.cairosquad.evolvefit.ui.screen.onBoarding | ||
|
|
||
| sealed class OnboardingScreenEffect { | ||
| object NavigateToLogin : OnboardingScreenEffect() | ||
| object NavigateToRegister : OnboardingScreenEffect() | ||
| } |
9 changes: 9 additions & 0 deletions
9
...mmonMain/kotlin/com/cairosquad/evolvefit/ui/screen/onBoarding/OnboardingScreenListener.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| package com.cairosquad.evolvefit.ui.screen.onBoarding | ||
|
|
||
| interface OnboardingScreenListener { | ||
| fun onChangeLanguage(language: OnboardingScreenState.Language) | ||
| fun toggleBottomSheet(isOpen: Boolean) | ||
| fun onSignUpClicked() | ||
| fun onLoginClicked() | ||
| fun onConfirmClicked() | ||
| } |
17 changes: 17 additions & 0 deletions
17
.../commonMain/kotlin/com/cairosquad/evolvefit/ui/screen/onBoarding/OnboardingScreenState.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.cairosquad.evolvefit.ui.screen.onBoarding | ||
|
|
||
| import evolvefit.composeapp.generated.resources.Res | ||
| import evolvefit.composeapp.generated.resources.arabic | ||
| import evolvefit.composeapp.generated.resources.english | ||
| import org.jetbrains.compose.resources.StringResource | ||
|
|
||
| data class OnboardingScreenState( | ||
| val selectedLanguage: Language = Language.ENGLISH, | ||
| val isBottomSheetOpen: Boolean = false, | ||
| val bottomSheetSelectedLanguage : Language = Language.ENGLISH | ||
| ) { | ||
| enum class Language( val displayNameRes: StringResource) { | ||
| ARABIC(Res.string.arabic), | ||
| ENGLISH(Res.string.english) | ||
| } | ||
| } |
15 changes: 15 additions & 0 deletions
15
composeApp/src/commonMain/kotlin/com/cairosquad/evolvefit/ui/util/NoRippleClick.kt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.cairosquad.evolvefit.ui.util | ||
|
|
||
| import androidx.compose.foundation.clickable | ||
| import androidx.compose.foundation.interaction.MutableInteractionSource | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.composed | ||
|
|
||
| fun Modifier.noRippleClickable(onClick: () -> Unit): Modifier = composed { | ||
| this.clickable( | ||
| indication = null, | ||
| interactionSource = remember { MutableInteractionSource() }) { | ||
| onClick() | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
replace this with svg