Skip to content
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

Prevent duplicate navigate up #6347

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -24,6 +25,6 @@ fun ContentBlockersInfoDialog(navigator: DestinationsNavigator) {
stringResource(id = R.string.settings_changes_effect_warning_content_blocker)
)
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
Expand Down Expand Up @@ -86,7 +87,7 @@ fun CreateCustomList(
state = state,
createCustomList = vm::createCustomList,
onInputChanged = vm::clearError,
onDismiss = backNavigator::navigateBack
onDismiss = dropUnlessResumed { backNavigator.navigateBack() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -20,6 +21,6 @@ private fun PreviewCustomDnsInfoDialog() {
fun CustomDnsInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.settings_changes_effect_warning_content_blocker),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand Down Expand Up @@ -52,7 +53,7 @@ fun DeleteCustomList(
state = state.value,
name = name,
onDelete = viewModel::deleteCustomList,
onBack = navigator::navigateBack
onBack = dropUnlessResumed { navigator.navigateBack() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.compose.dialog

import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -19,6 +20,6 @@ fun DeviceNameInfoDialog(navigator: DestinationsNavigator) {
appendLine()
append(stringResource(id = R.string.device_name_info_third_paragraph))
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.res.stringResource
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -18,18 +19,18 @@ import net.mullvad.mullvadvpn.compose.button.PrimaryButton
@Composable
fun DiscardChangesDialog(resultBackNavigator: ResultBackNavigator<Boolean>) {
AlertDialog(
onDismissRequest = resultBackNavigator::navigateBack,
onDismissRequest = dropUnlessResumed { resultBackNavigator.navigateBack() },
title = { Text(text = stringResource(id = R.string.discard_changes)) },
dismissButton = {
PrimaryButton(
modifier = Modifier.focusRequester(FocusRequester()),
onClick = resultBackNavigator::navigateBack,
onClick = dropUnlessResumed { resultBackNavigator.navigateBack() },
text = stringResource(id = R.string.cancel)
)
},
confirmButton = {
PrimaryButton(
onClick = { resultBackNavigator.navigateBack(result = true) },
onClick = dropUnlessResumed { resultBackNavigator.navigateBack(result = true) },
text = stringResource(id = R.string.discard)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand Down Expand Up @@ -75,7 +76,8 @@ fun DnsDialog(
viewModel::onDnsInputChange,
onSaveDnsClick = viewModel::onSaveDnsClick,
onRemoveDnsClick = viewModel::onRemoveDnsClick,
onDismiss = { resultNavigator.navigateBack(result = DnsDialogResult.Cancel) }
onDismiss =
dropUnlessResumed { resultNavigator.navigateBack(result = DnsDialogResult.Cancel) }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand Down Expand Up @@ -63,7 +64,7 @@ fun EditCustomListName(
state = state,
updateName = vm::updateCustomListName,
onInputChanged = vm::clearError,
onDismiss = backNavigator::navigateBack
onDismiss = dropUnlessResumed { backNavigator.navigateBack() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -26,6 +27,6 @@ fun LocalNetworkSharingInfoDialog(navigator: DestinationsNavigator) {
appendLine(stringResource(id = R.string.local_network_sharing_additional_info))
appendLine(textResource(id = R.string.local_network_sharing_ip_ranges))
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -20,6 +21,6 @@ private fun PreviewMalwareInfoDialog() {
fun MalwareInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.malware_info),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.EmptyResultBackNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
Expand Down Expand Up @@ -57,7 +58,7 @@ fun MtuDialog(mtuInitial: Mtu?, navigator: ResultBackNavigator<Boolean>) {
onInputChanged = viewModel::onInputChanged,
onSaveMtu = viewModel::onSaveClick,
onResetMtu = viewModel::onRestoreClick,
onDismiss = { navigator.navigateBack(true) }
onDismiss = dropUnlessResumed { navigator.navigateBack() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -20,6 +21,6 @@ private fun PreviewObfuscationInfoDialog() {
fun ObfuscationInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.obfuscation_info),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -21,6 +22,6 @@ fun QuantumResistanceInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.quantum_resistant_info_first_paragaph),
additionalInfo = stringResource(id = R.string.quantum_resistant_info_second_paragaph),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.sp
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.EmptyResultBackNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
Expand Down Expand Up @@ -42,7 +43,7 @@ private fun PreviewRemoveDeviceConfirmationDialog(
@Composable
fun RemoveDeviceConfirmationDialog(navigator: ResultBackNavigator<DeviceId>, device: Device) {
AlertDialog(
onDismissRequest = navigator::navigateBack,
onDismissRequest = dropUnlessResumed { navigator.navigateBack() },
icon = {
Icon(
modifier = Modifier.fillMaxWidth().height(Dimens.dialogIconHeight),
Expand All @@ -62,14 +63,14 @@ fun RemoveDeviceConfirmationDialog(navigator: ResultBackNavigator<DeviceId>, dev
},
dismissButton = {
NegativeButton(
onClick = { navigator.navigateBack(result = device.id) },
onClick = dropUnlessResumed { navigator.navigateBack(result = device.id) },
text = stringResource(id = R.string.confirm_removal)
)
},
confirmButton = {
PrimaryButton(
modifier = Modifier.focusRequester(FocusRequester()),
onClick = { navigator.navigateBack() },
onClick = dropUnlessResumed { navigator.navigateBack() },
text = stringResource(id = R.string.back)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.EmptyResultBackNavigator
import com.ramcosta.composedestinations.result.ResultBackNavigator
Expand All @@ -32,7 +33,7 @@ private fun PreviewReportProblemNoEmailDialog() {
@Composable
fun ReportProblemNoEmailDialog(resultBackNavigator: ResultBackNavigator<Boolean>) {
AlertDialog(
onDismissRequest = resultBackNavigator::navigateBack,
onDismissRequest = dropUnlessResumed { resultBackNavigator.navigateBack() },
icon = {
Icon(
painter = painterResource(id = R.drawable.icon_alert),
Expand All @@ -52,14 +53,14 @@ fun ReportProblemNoEmailDialog(resultBackNavigator: ResultBackNavigator<Boolean>
dismissButton = {
NegativeButton(
modifier = Modifier.fillMaxWidth(),
onClick = { resultBackNavigator.navigateBack(result = true) },
onClick = dropUnlessResumed { resultBackNavigator.navigateBack(result = true) },
text = stringResource(id = R.string.send_anyway)
)
},
confirmButton = {
PrimaryButton(
modifier = Modifier.fillMaxWidth(),
onClick = resultBackNavigator::navigateBack,
onClick = dropUnlessResumed { resultBackNavigator.navigateBack() },
text = stringResource(id = R.string.back)
)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.result.ResultBackNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand Down Expand Up @@ -43,7 +44,7 @@ fun ResetServerIpOverridesConfirmation(resultBackNavigator: ResultBackNavigator<
}
ResetServerIpOverridesConfirmationDialog(
onClearAllOverrides = vm::clearAllOverrides,
resultBackNavigator::navigateBack
dropUnlessResumed { resultBackNavigator.navigateBack() }
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -27,6 +28,6 @@ fun ServerIpOverridesInfoDialog(navigator: DestinationsNavigator) {
appendLine()
append(stringResource(id = R.string.server_ip_overrides_info_third_paragraph))
},
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package net.mullvad.mullvadvpn.compose.dialog
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand All @@ -21,6 +22,6 @@ private fun PreviewUdpOverTcpPortInfoDialog() {
fun UdpOverTcpPortInfoDialog(navigator: DestinationsNavigator) {
InfoDialog(
message = stringResource(id = R.string.udp_over_tcp_port_info),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.os.Parcelable
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.navigation.EmptyDestinationsNavigator
Expand Down Expand Up @@ -40,6 +41,6 @@ fun WireguardPortInfoDialog(
id = R.string.wireguard_port_info_port_range,
argument.portRanges.asString()
),
onDismiss = navigator::navigateUp
onDismiss = dropUnlessResumed { navigator.navigateUp() }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.graphics.compositeOver
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.lifecycle.compose.dropUnlessResumed
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.navigation.DestinationsNavigator
import com.ramcosta.composedestinations.spec.DestinationStyle
Expand All @@ -24,7 +25,7 @@ private fun PreviewVerificationPendingDialog() {
@Destination(style = DestinationStyle.Dialog::class)
@Composable
fun VerificationPendingDialog(navigator: DestinationsNavigator) {
VerificationPendingDialog(onClose = navigator::navigateUp)
VerificationPendingDialog(onClose = dropUnlessResumed { navigator.navigateUp() })
}

@Composable
Expand Down
Loading
Loading