Skip to content

Commit

Permalink
Handle navigate back
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuwu committed Dec 4, 2024
1 parent 4d01477 commit 1fa95b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class ArkCanvasFragment : Fragment() {
EditScreen(
imagePath = null,
imageUri = null,
fragmentManager = childFragmentManager,
navigateBack = { /*TODO*/ },
fragmentManager = requireActivity().supportFragmentManager,
navigateBack = { requireActivity().supportFragmentManager.popBackStackImmediate() },
launchedFromIntent = false,
maxResolution = Resolution(350, 720),
onSaveSvg = { /*TODO*/ },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,47 @@ package dev.arkbuilders.canvas.presentation.edit

import android.os.Build
import android.view.MotionEvent
import android.widget.Toast
import androidx.activity.compose.BackHandler
import androidx.annotation.RequiresApi
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.clickable
import androidx.compose.foundation.background
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.clickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.IntrinsicSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Icon
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Slider
import androidx.compose.material.Text
import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.KeyboardArrowDown
import androidx.compose.material.icons.filled.KeyboardArrowLeft
import androidx.compose.material.icons.filled.KeyboardArrowRight
import androidx.compose.material.icons.filled.KeyboardArrowUp
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
Expand Down Expand Up @@ -120,48 +118,11 @@ fun EditScreen(
viewModel = viewModel,
navigateBack = {
navigateBack()
viewModel.isLoaded = false
// viewModel.isLoaded = false
},
launchedFromIntent = launchedFromIntent,
)

BackHandler {
val editManager = viewModel.editManager
if (
editManager.isCropMode.value || editManager.isRotateMode.value ||
editManager.isResizeMode.value || editManager.isEyeDropperMode.value ||
editManager.isBlurMode.value
) {
viewModel.cancelOperation()
return@BackHandler
}
if (editManager.isZoomMode.value) {
editManager.toggleZoomMode()
return@BackHandler
}
if (editManager.isPanMode.value) {
editManager.togglePanMode()
return@BackHandler
}
if (editManager.canUndo.value) {
editManager.undo()
return@BackHandler
}
if (viewModel.exitConfirmed) {
if (launchedFromIntent)
context.getActivity()?.finish()
else
navigateBack()
return@BackHandler
}
if (!viewModel.exitConfirmed) {
Toast.makeText(context, "Tap back again to exit", Toast.LENGTH_SHORT)
.show()
viewModel.confirmExit()
return@BackHandler
}
}

HandleImageSavedEffect(viewModel, launchedFromIntent, navigateBack)

if (!showDefaultsDialog.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ class FilePickerFragment : Fragment() {
)
setContent {
// Set Content here
PickerScreen(fragmentManager = childFragmentManager,
PickerScreen(fragmentManager = requireActivity().supportFragmentManager,
onNavigateToEdit = { path, resolution ->
onNavigateToEdit(path, parentFragmentManager)
onNavigateToEdit(path, requireActivity().supportFragmentManager)
})
}
}
Expand All @@ -47,7 +47,8 @@ class FilePickerFragment : Fragment() {

fragmentManager
.beginTransaction()
.replace(R.id.canvas_content, canvasFragment)
.add(R.id.canvas_content, canvasFragment)
.addToBackStack(null)
.commit()
}

Expand Down

0 comments on commit 1fa95b6

Please sign in to comment.