From 32710f81011dd9a51660ffbbc68afba1c3505c42 Mon Sep 17 00:00:00 2001 From: Mugurell Date: Mon, 22 Aug 2022 18:45:36 +0300 Subject: [PATCH] [fenix] For https://github.com/mozilla-mobile/fenix/issues/26584 - Add vertical offset support to the CFR composable. --- .../main/java/org/mozilla/fenix/compose/cfr/CFRPopup.kt | 8 ++++++++ .../mozilla/fenix/compose/cfr/CFRPopupFullscreenLayout.kt | 5 +++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopup.kt b/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopup.kt index 49e96719ec..84aeaa263d 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopup.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopup.kt @@ -25,6 +25,8 @@ import java.lang.ref.WeakReference * @property overlapAnchor How the popup's indicator will be shown in relation to the anchor: * - true - indicator will be shown exactly in the middle horizontally and vertically * - false - indicator will be shown horizontally in the middle of the anchor but immediately below or above it + * @property popupVerticalOffset Vertical distance between the indicator arrow and the anchor. + * This only applies if [overlapAnchor] is `false`. * @property indicatorArrowStartOffset Maximum distance between the popup start and the indicator arrow. * If there isn't enough space this could automatically be overridden up to 0 such that * the indicator arrow will be pointing to the middle of the anchor. @@ -36,6 +38,7 @@ data class CFRPopupProperties( val dismissOnBackPress: Boolean = true, val dismissOnClickOutside: Boolean = true, val overlapAnchor: Boolean = false, + val popupVerticalOffset: Dp = CFRPopup.DEFAULT_VERTICAL_OFFSET.dp, val indicatorArrowStartOffset: Dp = CFRPopup.DEFAULT_INDICATOR_START_OFFSET.dp, ) @@ -145,5 +148,10 @@ class CFRPopup( * Corner radius for the popup body. */ internal const val DEFAULT_CORNER_RADIUS = 12 + + /** + * Vertical distance between the indicator arrow and the anchor. + */ + internal const val DEFAULT_VERTICAL_OFFSET = 9 } } diff --git a/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopupFullscreenLayout.kt b/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopupFullscreenLayout.kt index ac5a362755..4174782e7c 100644 --- a/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopupFullscreenLayout.kt +++ b/app/src/main/java/org/mozilla/fenix/compose/cfr/CFRPopupFullscreenLayout.kt @@ -201,13 +201,14 @@ internal class CFRPopupFullScreenLayout( UP -> { when (properties.overlapAnchor) { true -> anchorLocation.last() + anchor.height / 2 - else -> anchorLocation.last() + anchor.height + else -> anchorLocation.last() + anchor.height + properties.popupVerticalOffset.toPx() } } DOWN -> { when (properties.overlapAnchor) { true -> anchorLocation.last() - popupContentSize.height + anchor.height / 2 - else -> anchorLocation.last() - popupContentSize.height + else -> anchorLocation.last() - popupContentSize.height - + properties.popupVerticalOffset.toPx() } } }