Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement await shows balloon for Compose #480

Merged
merged 1 commit into from
Aug 28, 2023
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
14 changes: 14 additions & 0 deletions balloon-compose/api/balloon-compose.api
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ public final class com/skydoves/balloon/compose/BalloonKt {
}

public abstract interface class com/skydoves/balloon/compose/BalloonWindow {
public abstract fun awaitAlign (Lcom/skydoves/balloon/BalloonAlign;Landroid/view/View;Ljava/util/List;IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun awaitAlignBottom (IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun awaitAlignLeft (IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun awaitAlignRight (IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun awaitAlignTop (IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun awaitAsDropDown (IILkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun awaitAtCenter (IILcom/skydoves/balloon/BalloonCenterAlign;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun clearAllPreferences ()V
public abstract fun dismiss ()V
public abstract fun dismissWithDelay (J)Z
Expand Down Expand Up @@ -54,6 +61,13 @@ public abstract interface class com/skydoves/balloon/compose/BalloonWindow {
}

public final class com/skydoves/balloon/compose/BalloonWindow$DefaultImpls {
public static synthetic fun awaitAlign$default (Lcom/skydoves/balloon/compose/BalloonWindow;Lcom/skydoves/balloon/BalloonAlign;Landroid/view/View;Ljava/util/List;IILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitAlignBottom$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitAlignLeft$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitAlignRight$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitAlignTop$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitAsDropDown$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun awaitAtCenter$default (Lcom/skydoves/balloon/compose/BalloonWindow;IILcom/skydoves/balloon/BalloonCenterAlign;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object;
public static synthetic fun relayShowAlign$default (Lcom/skydoves/balloon/compose/BalloonWindow;Lcom/skydoves/balloon/BalloonAlign;Lcom/skydoves/balloon/Balloon;IIILjava/lang/Object;)Lcom/skydoves/balloon/Balloon;
public static synthetic fun relayShowAlignBottom$default (Lcom/skydoves/balloon/compose/BalloonWindow;Lcom/skydoves/balloon/Balloon;IIILjava/lang/Object;)Lcom/skydoves/balloon/Balloon;
public static synthetic fun relayShowAlignLeft$default (Lcom/skydoves/balloon/compose/BalloonWindow;Lcom/skydoves/balloon/Balloon;IIILjava/lang/Object;)Lcom/skydoves/balloon/Balloon;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,45 @@ internal class BalloonComposeView(
override fun showAlignBottom(xOff: Int, yOff: Int): Unit =
balloon.showAlignBottom(anchorView, xOff, yOff)

override suspend fun awaitAtCenter(
xOff: Int,
yOff: Int,
centerAlign: BalloonCenterAlign,
) = balloon.awaitAtCenter(anchorView, xOff, yOff, centerAlign)

override suspend fun awaitAsDropDown(
xOff: Int,
yOff: Int,
) = balloon.awaitAsDropDown(anchorView, xOff, yOff)

override suspend fun awaitAlignTop(
xOff: Int,
yOff: Int,
) = balloon.awaitAlignTop(anchorView, xOff, yOff)

override suspend fun awaitAlignBottom(
xOff: Int,
yOff: Int,
) = balloon.awaitAlignBottom(anchorView, xOff, yOff)

override suspend fun awaitAlignRight(
xOff: Int,
yOff: Int,
) = balloon.awaitAlignRight(anchorView, xOff, yOff)

override suspend fun awaitAlignLeft(
xOff: Int,
yOff: Int,
) = balloon.awaitAlignLeft(anchorView, xOff, yOff)

override suspend fun awaitAlign(
align: BalloonAlign,
mainAnchor: View,
subAnchorList: List<View>,
xOff: Int,
yOff: Int,
) = balloon.awaitAlign(align, mainAnchor, subAnchorList, xOff, yOff)

override fun relayShowAlignBottom(balloon: Balloon, xOff: Int, yOff: Int): Balloon =
balloon.relayShowAlignBottom(balloon, anchorView, xOff, yOff)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ import com.skydoves.balloon.OnBalloonInitializedListener
import com.skydoves.balloon.OnBalloonOutsideTouchListener
import com.skydoves.balloon.OnBalloonOverlayClickListener
import com.skydoves.balloon.animations.InternalBalloonApi
import com.skydoves.balloon.showAlign
import com.skydoves.balloon.showAlignBottom
import com.skydoves.balloon.showAlignLeft
import com.skydoves.balloon.showAlignRight
import com.skydoves.balloon.showAlignTop
import com.skydoves.balloon.showAsDropDown
import com.skydoves.balloon.showAtCenter

/**
* BalloonWindow is an interface that define all executable behaviors of the balloon's window.
Expand All @@ -56,6 +63,20 @@ public interface BalloonWindow {
centerAlign: BalloonCenterAlign = BalloonCenterAlign.TOP,
)

/**
* Coroutine alternative for [showAtCenter]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
* @param centerAlign A rule for deciding the alignment of the balloon.
*/
public suspend fun awaitAtCenter(
xOff: Int = 0,
yOff: Int = 0,
centerAlign: BalloonCenterAlign = BalloonCenterAlign.TOP,
)

/**
* Shows the balloon on an anchor view as the center alignment with x-off and y-off and shows the next balloon sequentially.
* This function returns the next balloon.
Expand Down Expand Up @@ -84,6 +105,15 @@ public interface BalloonWindow {
*/
public fun showAsDropDown(xOff: Int = 0, yOff: Int = 0)

/**
* Coroutine alternative for [showAsDropDown]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
*/
public suspend fun awaitAsDropDown(xOff: Int = 0, yOff: Int = 0)

/**
* Shows the balloon on an anchor view as drop down with x-off and y-off and shows the next balloon sequentially.
* This function returns the next balloon.
Expand All @@ -110,6 +140,15 @@ public interface BalloonWindow {
*/
public fun showAlignTop(xOff: Int = 0, yOff: Int = 0)

/**
* Coroutine alternative for [showAlignTop]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
*/
public suspend fun awaitAlignTop(xOff: Int = 0, yOff: Int = 0)

/**
* Shows the balloon on an anchor view as the top alignment with x-off and y-off and shows the next balloon sequentially.
* This function returns the next balloon.
Expand All @@ -136,6 +175,15 @@ public interface BalloonWindow {
*/
public fun showAlignBottom(xOff: Int = 0, yOff: Int = 0)

/**
* Coroutine alternative for [showAlignBottom]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
*/
public suspend fun awaitAlignBottom(xOff: Int = 0, yOff: Int = 0)

/**
* Shows the balloon on an anchor view as the bottom alignment with x-off and y-off
* and shows the next balloon sequentially.
Expand Down Expand Up @@ -163,6 +211,15 @@ public interface BalloonWindow {
*/
public fun showAlignRight(xOff: Int = 0, yOff: Int = 0)

/**
* Coroutine alternative for [showAlignRight]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
*/
public suspend fun awaitAlignRight(xOff: Int = 0, yOff: Int = 0)

/**
* Shows the balloon on an anchor view as the right alignment with x-off and y-off
* and shows the next balloon sequentially.
Expand Down Expand Up @@ -190,6 +247,15 @@ public interface BalloonWindow {
*/
public fun showAlignLeft(xOff: Int = 0, yOff: Int = 0)

/**
* Coroutine alternative for [showAlignLeft]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
*/
public suspend fun awaitAlignLeft(xOff: Int = 0, yOff: Int = 0)

/**
* Shows the balloon on an anchor view as the left alignment with x-off and y-off
* and shows the next balloon sequentially.
Expand Down Expand Up @@ -226,6 +292,24 @@ public interface BalloonWindow {
yOff: Int = 0,
)

/**
* Coroutine alternative for [showAlign]. This method suspends until the popup is displayed.
* Can be used to show popups sequentially without using relay methods.
*
* @param align Decides where the balloon should be placed.
* @param mainAnchor A target view which popup will be displayed.
* @param subAnchorList A list of anchors to display focuses on the overlay view.
* @param xOff A horizontal offset from the anchor in pixels.
* @param yOff A vertical offset from the anchor in pixels.
*/
public suspend fun awaitAlign(
align: BalloonAlign,
mainAnchor: View,
subAnchorList: List<View> = listOf(),
xOff: Int = 0,
yOff: Int = 0,
)

/**
* Shows the balloon on an anchor view depending on the [align] alignment with x-off and y-off
* and shows the next balloon sequentially.
Expand Down