Skip to content

Commit

Permalink
Show close icon when modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Dec 23, 2024
1 parent 8ef06bf commit b37b14c
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ fun AppInfo(navigator: DestinationsNavigator) {
AppInfo(
state = state,
onBackClick = dropUnlessResumed { navigator.navigateUp() },
navigateToChangelog = dropUnlessResumed { navigator.navigate(ChangelogDestination) },
navigateToChangelog =
dropUnlessResumed { navigator.navigate(ChangelogDestination(ChangelogNavArgs())) },
openAppListing = dropUnlessResumed { vm.openAppListing() },
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.ramcosta.composedestinations.annotation.RootGraph
import net.mullvad.mullvadvpn.R
import net.mullvad.mullvadvpn.compose.button.PrimaryButton
import net.mullvad.mullvadvpn.compose.component.NavigateBackIconButton
import net.mullvad.mullvadvpn.compose.component.NavigateCloseIconButton
import net.mullvad.mullvadvpn.compose.component.ScaffoldWithMediumTopBar
import net.mullvad.mullvadvpn.compose.extensions.createOpenFullChangeLogHook
import net.mullvad.mullvadvpn.compose.transitions.SlideInFromRightTransition
Expand All @@ -37,7 +38,12 @@ import net.mullvad.mullvadvpn.viewmodel.ChangelogUiState
import net.mullvad.mullvadvpn.viewmodel.ChangelogViewModel
import org.koin.androidx.compose.koinViewModel

@Destination<RootGraph>(style = SlideInFromRightTransition::class)
data class ChangelogNavArgs(val isModal: Boolean = false)

@Destination<RootGraph>(
style = SlideInFromRightTransition::class,
navArgs = ChangelogNavArgs::class,
)
@Composable
fun Changelog(navController: NavController) {
val viewModel = koinViewModel<ChangelogViewModel>()
Expand Down Expand Up @@ -68,7 +74,13 @@ fun ChangelogScreen(

ScaffoldWithMediumTopBar(
appBarTitle = stringResource(id = R.string.changelog_title),
navigationIcon = { NavigateBackIconButton(onNavigateBack = onBackClick) },
navigationIcon = {
if (state.isModal) {
NavigateCloseIconButton(onBackClick)
} else {
NavigateBackIconButton(onNavigateBack = onBackClick)
}
},
) { modifier ->
Column(modifier = modifier.padding(horizontal = Dimens.mediumPadding)) {
Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ fun Connect(
onSwitchLocationClick = dropUnlessResumed { navigator.navigate(SelectLocationDestination) },
onOpenAppListing = connectViewModel::openAppListing,
onManageAccountClick = connectViewModel::onManageAccountClick,
onChangelogClick = dropUnlessResumed { navigator.navigate(ChangelogDestination) },
onChangelogClick =
dropUnlessResumed { navigator.navigate(ChangelogDestination(ChangelogNavArgs(true))) },
onDismissChangelogClick = connectViewModel::dismissNewChangelogNotification,
onSettingsClick = dropUnlessResumed { navigator.navigate(SettingsDestination) },
onAccountClick = dropUnlessResumed { navigator.navigate(AccountDestination) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ val uiModule = module {

// View models
viewModel { AccountViewModel(get(), get(), get(), IS_PLAY_BUILD) }
viewModel { ChangelogViewModel(get(), get()) }
viewModel { ChangelogViewModel(get(), get(), get()) }
viewModel {
AppInfoViewModel(get(), get(), get(), IS_PLAY_BUILD, get(named(SELF_PACKAGE_NAME)))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package net.mullvad.mullvadvpn.viewmodel

import android.os.Parcelable
import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.ramcosta.composedestinations.generated.destinations.ChangelogDestination
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
Expand All @@ -14,14 +16,20 @@ import net.mullvad.mullvadvpn.repository.ChangelogRepository

class ChangelogViewModel(
private val changelogRepository: ChangelogRepository,
savedStateHandle: SavedStateHandle,
buildVersion: BuildVersion,
) : ViewModel() {
private val navArgs = ChangelogDestination.argsFrom(savedStateHandle)
private val _uiSideEffect = Channel<ChangeLogSideEffect>()
val uiSideEffect = _uiSideEffect.receiveAsFlow()

val uiState: StateFlow<ChangelogUiState> =
MutableStateFlow(
ChangelogUiState(buildVersion.name, changelogRepository.getLastVersionChanges())
ChangelogUiState(
navArgs.isModal,
buildVersion.name,
changelogRepository.getLastVersionChanges(),
)
)

fun dismissChangelogNotification() =
Expand All @@ -35,4 +43,9 @@ sealed interface ChangeLogSideEffect {
object OpenFullChangelog : ChangeLogSideEffect
}

@Parcelize data class ChangelogUiState(val version: String, val changes: List<String>) : Parcelable
@Parcelize
data class ChangelogUiState(
val isModal: Boolean = false,
val version: String,
val changes: List<String>,
) : Parcelable

0 comments on commit b37b14c

Please sign in to comment.