Skip to content
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 @@ -411,7 +411,6 @@ open class ObjectSetFragment :
ViewersWidget(
state = vm.viewersWidgetState.collectAsStateWithLifecycle().value,
action = vm::onViewersWidgetAction,
scope = lifecycleScope
)
}
}
Expand All @@ -422,7 +421,6 @@ open class ObjectSetFragment :
ViewerEditWidget(
state = vm.viewerEditWidgetState.collectAsStateWithLifecycle().value,
action = vm::onViewerEditWidgetAction,
scope = lifecycleScope
)
}
}
Expand All @@ -433,7 +431,6 @@ open class ObjectSetFragment :
ViewerLayoutWidget(
uiState = vm.viewerLayoutWidgetState.collectAsStateWithLifecycle().value,
action = vm::onViewerLayoutWidgetAction,
scope = lifecycleScope
)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
package com.anytypeio.anytype.core_ui.widgets.dv

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.core.tween
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.slideInVertically
import androidx.compose.animation.slideOutVertically
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.ime
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.windowInsetsPadding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.BasicTextField
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.FractionalThreshold
import androidx.compose.material.Text
import androidx.compose.material.rememberSwipeableState
import androidx.compose.material.swipeable
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.ModalBottomSheet
import androidx.compose.material3.rememberModalBottomSheetState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -45,13 +37,10 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.focus.onFocusChanged
import androidx.compose.ui.geometry.Rect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.SolidColor
import androidx.compose.ui.graphics.painter.Painter
import androidx.compose.ui.layout.boundsInRoot
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.SoftwareKeyboardController
Expand All @@ -62,103 +51,57 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.dp
import androidx.constraintlayout.compose.ConstraintLayout
import androidx.constraintlayout.compose.Dimension
import com.anytypeio.anytype.core_models.DVViewerType
import com.anytypeio.anytype.core_ui.R
import com.anytypeio.anytype.core_ui.foundation.Divider
import com.anytypeio.anytype.core_ui.foundation.Dragger
import com.anytypeio.anytype.core_ui.foundation.noRippleClickable
import com.anytypeio.anytype.core_ui.foundation.noRippleThrottledClickable
import com.anytypeio.anytype.core_ui.views.Caption1Medium
import com.anytypeio.anytype.core_ui.views.Title1
import com.anytypeio.anytype.core_ui.views.UXBody
import com.anytypeio.anytype.core_ui.widgets.DragStates
import com.anytypeio.anytype.presentation.sets.ViewEditAction
import com.anytypeio.anytype.presentation.sets.ViewerEditWidgetUi
import com.anytypeio.anytype.presentation.sets.isVisible
import kotlin.math.roundToInt
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

@OptIn(ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class)
@OptIn(ExperimentalMaterialApi::class, ExperimentalComposeUiApi::class,
ExperimentalMaterial3Api::class
)
@Composable
fun ViewerEditWidget(
state: ViewerEditWidgetUi,
action: (ViewEditAction) -> Unit,
scope: CoroutineScope
) {

val bottomSheetState = rememberModalBottomSheetState(
skipPartiallyExpanded = true
)

val focusRequester = remember { FocusRequester() }
val focusManager = LocalFocusManager.current
val keyboardController = LocalSoftwareKeyboardController.current

Box(
modifier = Modifier.fillMaxSize(),
contentAlignment = Alignment.BottomStart,
) {

val currentState by rememberUpdatedState(state)
val swipeableState = rememberSwipeableState(DragStates.VISIBLE)
val keyboardController = LocalSoftwareKeyboardController.current

AnimatedVisibility(
visible = currentState.isVisible(),
enter = fadeIn(),
exit = fadeOut(tween(100))
) {
Box(
Modifier
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.4f))
.noRippleClickable { action(ViewEditAction.Dismiss) }
)
}

if (swipeableState.isAnimationRunning && swipeableState.targetValue == DragStates.DISMISSED) {
DisposableEffect(Unit) {
onDispose {
keyboardController?.hide()
focusManager.clearFocus()
action(ViewEditAction.Dismiss)
}
}
}

if (!currentState.isVisible()) {
DisposableEffect(Unit) {
onDispose {
scope.launch { swipeableState.snapTo(DragStates.VISIBLE) }
}
}
}

val sizePx =
with(LocalDensity.current) { LocalConfiguration.current.screenHeightDp.dp.toPx() }

AnimatedVisibility(
visible = currentState.isVisible(),
enter = slideInVertically { it },
exit = slideOutVertically { it },
if (state is ViewerEditWidgetUi.Data) {
ModalBottomSheet(
modifier = Modifier
.swipeable(state = swipeableState,
orientation = Orientation.Vertical,
anchors = mapOf(
0f to DragStates.VISIBLE, sizePx to DragStates.DISMISSED
),
thresholds = { _, _ -> FractionalThreshold(0.3f) })
.offset { IntOffset(0, swipeableState.offset.value.roundToInt()) }
) {
if (state is ViewerEditWidgetUi.Data) {
.windowInsetsPadding(WindowInsets.ime)
.padding(start = 8.dp, end = 8.dp, bottom = 30.dp)
.fillMaxWidth()
.wrapContentHeight(),
scrimColor = colorResource(id = R.color.modal_screen_outside_background),
containerColor = colorResource(id = R.color.background_secondary),
shape = RoundedCornerShape(16.dp),
onDismissRequest = { action(ViewEditAction.Dismiss) },
sheetState = bottomSheetState,
dragHandle = { DragHandle() },
content = {
ViewerEditWidgetContent(state, focusRequester, keyboardController) {
focusManager.clearFocus()
keyboardController?.hide()
action.invoke(it)
}
}
}
)
}
}

Expand All @@ -179,24 +122,14 @@ fun ViewerEditWidgetContent(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(start = 8.dp, end = 8.dp, bottom = 15.dp)
.background(
color = colorResource(id = R.color.background_secondary),
shape = RoundedCornerShape(size = 16.dp)
),
//.padding(start = 8.dp, end = 8.dp, bottom = 15.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.wrapContentHeight()
.padding(bottom = 16.dp, start = 20.dp, end = 20.dp)
) {
Box(modifier = Modifier
.fillMaxWidth()
.padding(top = 6.dp, bottom = 6.dp)
) {
Dragger(modifier = Modifier.align(Alignment.Center))
}
Box(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -477,5 +410,5 @@ fun PreviewViewerEditWidget() {
id = "1",
isActive = false
)
ViewerEditWidget(state = state, action = {}, scope = CoroutineScope(Dispatchers.Main))
ViewerEditWidget(state = state, action = {})
}
Loading
Loading