From a1f95f0db75629cdbc157646e69e22fd6526d58b Mon Sep 17 00:00:00 2001 From: skydoves Date: Wed, 27 Dec 2023 22:28:53 +0900 Subject: [PATCH] Implement updateAlign relevant methods for Compose --- balloon-compose/api/balloon-compose.api | 10 +++++ .../balloon/compose/BalloonComposeView.kt | 24 ++++++++++ .../skydoves/balloon/compose/BalloonWindow.kt | 45 +++++++++++++++++++ 3 files changed, 79 insertions(+) diff --git a/balloon-compose/api/balloon-compose.api b/balloon-compose/api/balloon-compose.api index 2d1e96be..74142d28 100644 --- a/balloon-compose/api/balloon-compose.api +++ b/balloon-compose/api/balloon-compose.api @@ -86,6 +86,11 @@ public abstract interface class com/skydoves/balloon/compose/BalloonWindow { public abstract fun showAsDropDown (II)V public abstract fun showAtCenter (IILcom/skydoves/balloon/BalloonCenterAlign;)V public abstract fun update (II)V + public abstract fun updateAlign (Lcom/skydoves/balloon/BalloonAlign;II)V + public abstract fun updateAlignBottom (II)V + public abstract fun updateAlignEnd (II)V + public abstract fun updateAlignStart (II)V + public abstract fun updateAlignTop (II)V public abstract fun updateSizeOfBalloonCard (II)V } @@ -116,6 +121,11 @@ public final class com/skydoves/balloon/compose/BalloonWindow$DefaultImpls { public static synthetic fun showAsDropDown$default (Lcom/skydoves/balloon/compose/BalloonWindow;IIILjava/lang/Object;)V public static synthetic fun showAtCenter$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILcom/skydoves/balloon/BalloonCenterAlign;ILjava/lang/Object;)V public static synthetic fun update$default (Lcom/skydoves/balloon/compose/BalloonWindow;IIILjava/lang/Object;)V + public static synthetic fun updateAlign$default (Lcom/skydoves/balloon/compose/BalloonWindow;Lcom/skydoves/balloon/BalloonAlign;IIILjava/lang/Object;)V + public static synthetic fun updateAlignBottom$default (Lcom/skydoves/balloon/compose/BalloonWindow;IIILjava/lang/Object;)V + public static synthetic fun updateAlignEnd$default (Lcom/skydoves/balloon/compose/BalloonWindow;IIILjava/lang/Object;)V + public static synthetic fun updateAlignStart$default (Lcom/skydoves/balloon/compose/BalloonWindow;IIILjava/lang/Object;)V + public static synthetic fun updateAlignTop$default (Lcom/skydoves/balloon/compose/BalloonWindow;IIILjava/lang/Object;)V } public final class com/skydoves/balloon/compose/ComposableSingletons$BalloonComposeViewKt { diff --git a/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonComposeView.kt b/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonComposeView.kt index 3a194ed5..63306996 100644 --- a/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonComposeView.kt +++ b/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonComposeView.kt @@ -222,6 +222,30 @@ internal class BalloonComposeView( yOff: Int, ): Balloon = balloon.relayShowAlign(align, balloon, anchorView, xOff, yOff) + override fun updateAlignTop(xOff: Int, yOff: Int) { + balloon.updateAlignTop(anchorView, xOff, yOff) + } + + override fun updateAlignBottom(xOff: Int, yOff: Int) { + balloon.updateAlignBottom(anchorView, xOff, yOff) + } + + override fun updateAlignEnd(xOff: Int, yOff: Int) { + balloon.updateAlignEnd(anchorView, xOff, yOff) + } + + override fun updateAlignStart(xOff: Int, yOff: Int) { + balloon.updateAlignStart(anchorView, xOff, yOff) + } + + override fun updateAlign(align: BalloonAlign, xOff: Int, yOff: Int) { + balloon.updateAlign(align, anchorView, xOff, yOff) + } + + @Deprecated( + "Use updateAlign instead.", + replaceWith = ReplaceWith("updateAlign(BalloonAlign.Top, xOff, yOff)"), + ) override fun update(xOff: Int, yOff: Int): Unit = balloon.update(anchorView, xOff, yOff) override fun showAlign( diff --git a/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonWindow.kt b/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonWindow.kt index 9fe26d87..5fdb41c8 100644 --- a/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonWindow.kt +++ b/balloon-compose/src/main/kotlin/com/skydoves/balloon/compose/BalloonWindow.kt @@ -402,6 +402,47 @@ public interface BalloonWindow { yOff: Int = 0, ): Balloon + /** + * Update the balloon on an [anchorView] as the top alignment with x-off and y-off. + * + * @param xOff A horizontal offset from the anchor in pixels. + * @param yOff A vertical offset from the anchor in pixels. + */ + public fun updateAlignTop(xOff: Int = 0, yOff: Int = 0) + + /** + * Update the balloon on an [anchorView] as the bottom alignment with x-off and y-off. + * + * @param xOff A horizontal offset from the anchor in pixels. + * @param yOff A vertical offset from the anchor in pixels. + */ + public fun updateAlignBottom(xOff: Int = 0, yOff: Int = 0) + + /** + * Update the balloon on an [anchorView] as the end alignment with x-off and y-off. + * + * @param xOff A horizontal offset from the anchor in pixels. + * @param yOff A vertical offset from the anchor in pixels. + */ + public fun updateAlignEnd(xOff: Int = 0, yOff: Int = 0) + + /** + * Update the balloon on an [anchorView] as the start alignment with x-off and y-off. + * + * @param xOff A horizontal offset from the anchor in pixels. + * @param yOff A vertical offset from the anchor in pixels. + */ + public fun updateAlignStart(xOff: Int = 0, yOff: Int = 0) + + /** + * Update the balloon on an [anchorView] as the bottom alignment with x-off and y-off. + * + * @param align Decides where the balloon should be placed. + * @param xOff A horizontal offset from the anchor in pixels. + * @param yOff A vertical offset from the anchor in pixels. + */ + public fun updateAlign(align: BalloonAlign, xOff: Int = 0, yOff: Int = 0) + /** * updates popup and arrow position of the popup based on * a new target anchor view with additional x-off and y-off. @@ -409,6 +450,10 @@ public interface BalloonWindow { * @param xOff A horizontal offset from the anchor in pixels. * @param yOff A vertical offset from the anchor in pixels. */ + @Deprecated( + "Use updateAlign instead.", + replaceWith = ReplaceWith("updateAlign(BalloonAlign.Top, xOff, yOff)"), + ) public fun update(xOff: Int = 0, yOff: Int = 0) /** updates the size of the balloon card. */