Skip to content

Commit 38ced55

Browse files
authored
Merge pull request #81 from what3words/fix/ui-issues
Fix UI issues
2 parents 3f3c26e + 8247114 commit 38ced55

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

lib/src/main/java/com/what3words/ocr/components/ui/W3WOcrScanner.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ private const val BUTTON_CONTROL_MARGIN = 48 //dp
9999
private const val BOTTOM_SHEET_PEEK_HEIGHT = 65 //dp
100100
private const val BOTTOM_SHEET_NOT_FOUND_HEIGHT = 180 //dp
101101
private const val DRAG_SENSITIVITY_FACTOR = 300f //dp
102+
private const val PADDING_FULL_SCREEN_SHEET = 4 //dp
102103

103104
private enum class SheetState { PEEK, CONTENT, FULL }
104105

@@ -668,7 +669,7 @@ private fun ScannerContent(
668669
sheetState = sheetState,
669670
dragOffset = dragOffset,
670671
maxBottomSheetHeight = maxBottomSheetHeight,
671-
fullScreenHeight = with(density) { parentHeight.toDp() } - scannerLayoutConfig.contentPadding.calculateTopPadding() - scannerLayoutConfig.contentPadding.calculateBottomPadding(),
672+
fullScreenHeight = with(density) { parentHeight.toDp() } - scannerLayoutConfig.contentPadding.calculateTopPadding(),
672673
peekHeight = peekHeight + scannerLayoutConfig.contentPadding.calculateBottomPadding(),
673674
isImageCaptured = ocrScannerState.capturedImage != null
674675
).value,
@@ -677,8 +678,7 @@ private fun ScannerContent(
677678
)
678679

679680
// Calculate maximum allowed height for bottom sheet
680-
maxBottomSheetHeight =
681-
remember(cropAreaBottom, ocrScannerState.capturedImage) {
681+
maxBottomSheetHeight = remember(cropAreaBottom, parentHeight, controlButtonBarHeight, ocrScannerState.capturedImage) {
682682
with(density) {
683683
val parentHeightDp = parentHeight.toDp()
684684
val controlBarHeight = controlButtonBarHeight.toDp()
@@ -796,7 +796,12 @@ private fun ScannerContent(
796796
top.linkTo(topBackground.bottom)
797797
width = Dimension.fillToConstraints
798798
height =
799-
Dimension.ratio(if (orientation == ORIENTATION_PORTRAIT) "2:1.5" else "3.1")
799+
Dimension.percent(
800+
when {
801+
orientation == ORIENTATION_PORTRAIT -> 0.3f // 30% of screen height in portrait
802+
else -> 0.45f // 45% of screen height in landscape
803+
}
804+
)
800805
}
801806
.onGloballyPositioned {
802807
cropAreaBottom = it.boundsInParent().bottom
@@ -1157,7 +1162,7 @@ private fun calculateTargetHeight(
11571162
// Calculate the base height (maxBottomSheetHeight) and target height (full screen or adjusted full screen).
11581163
val base = maxBottomSheetHeight.value
11591164
val target =
1160-
if (!isImageCaptured) fullScreenHeight.value else fullScreenHeight.value - TopAppBarDefaults.TopAppBarExpandedHeight.value
1165+
if (!isImageCaptured) fullScreenHeight.value else fullScreenHeight.value - TopAppBarDefaults.TopAppBarExpandedHeight.value - PADDING_FULL_SCREEN_SHEET.dp.value
11611166

11621167
// Calculate the interpolation factor based on the negative drag offset (dragging up).
11631168
// Dividing by dragSensitivityFactor scales the drag distance, determining how much drag is needed
@@ -1176,7 +1181,7 @@ private fun calculateTargetHeight(
11761181
// When dragging down from FULL state:
11771182
// Calculate the base height (full screen or adjusted full screen) and target height (maxBottomSheetHeight).
11781183
val base =
1179-
if (!isImageCaptured) fullScreenHeight.value else fullScreenHeight.value - TopAppBarDefaults.TopAppBarExpandedHeight.value
1184+
if (!isImageCaptured) fullScreenHeight.value else fullScreenHeight.value - TopAppBarDefaults.TopAppBarExpandedHeight.value - PADDING_FULL_SCREEN_SHEET.dp.value
11801185
val target = maxBottomSheetHeight.value
11811186

11821187
// Calculate the interpolation factor based on the positive drag offset (dragging down).
@@ -1198,7 +1203,7 @@ private fun calculateTargetHeight(
11981203
// Non-dragging states just return the height defined for that state.
11991204
SheetState.PEEK -> peekHeight
12001205
SheetState.CONTENT -> maxBottomSheetHeight
1201-
SheetState.FULL -> if (!isImageCaptured) fullScreenHeight else fullScreenHeight - TopAppBarDefaults.TopAppBarExpandedHeight
1206+
SheetState.FULL -> if (!isImageCaptured) fullScreenHeight else fullScreenHeight - TopAppBarDefaults.TopAppBarExpandedHeight - PADDING_FULL_SCREEN_SHEET.dp
12021207
}
12031208
}
12041209
}

0 commit comments

Comments
 (0)