@@ -36,11 +36,14 @@ import androidx.compose.ui.layout.boundsInRoot
3636import androidx.compose.ui.layout.onGloballyPositioned
3737import androidx.compose.ui.layout.positionInRoot
3838import androidx.compose.ui.platform.LocalConfiguration
39+ import androidx.compose.ui.platform.LocalContext
3940import androidx.compose.ui.platform.LocalDensity
4041import androidx.compose.ui.text.font.FontWeight
4142import androidx.compose.ui.unit.dp
4243import androidx.compose.ui.unit.sp
4344import kotlinx.coroutines.delay
45+ import java.util.Timer
46+ import kotlin.concurrent.schedule
4447import kotlin.math.max
4548import kotlin.math.min
4649import kotlin.math.pow
@@ -53,19 +56,27 @@ import kotlin.math.sqrt
5356@Composable
5457fun ShowCaseTarget (
5558 targets : SnapshotStateMap <String , ShowcaseProperty >,
59+ isEnableAutoShowCase : Boolean = false,
60+ key : String ,
5661 onShowCaseCompleted : () -> Unit
5762) {
63+ val preferences = Preferences (context = LocalContext .current)
5864 val uniqueTargets = targets.values.sortedBy { it.index }
5965 var currentTargetIndex by remember { mutableStateOf(0 ) }
6066 val currentTarget = if (uniqueTargets.isNotEmpty() && currentTargetIndex < uniqueTargets.size)
6167 uniqueTargets[currentTargetIndex]
6268 else
6369 null
6470
71+ if (preferences.getShowing(key)) {
72+ return
73+ }
74+
6575 currentTarget?.let {
66- IntroShowCase (targets = it) {
76+ IntroShowCase (targets = it, isAutomaticShowcase = isEnableAutoShowCase ) {
6777 if (++ currentTargetIndex >= uniqueTargets.size) {
6878 onShowCaseCompleted()
79+ preferences.show(key)
6980 }
7081 }
7182 }
@@ -77,7 +88,9 @@ fun ShowCaseTarget(
7788 * @param onShowCaseCompleted do the needful on completing showcase view.
7889 */
7990@Composable
80- fun IntroShowCase (targets : ShowcaseProperty , onShowCaseCompleted : () -> Unit ) {
91+ fun IntroShowCase (
92+ targets : ShowcaseProperty , isAutomaticShowcase : Boolean = false, onShowCaseCompleted : () -> Unit
93+ ) {
8194 val targetRect = targets.coordinates.boundsInRoot()
8295 val targetRadius = targetRect.maxDimension / 2f + 20
8396 val xOffset = targetRect.topLeft.x
@@ -139,10 +152,16 @@ fun IntroShowCase(targets: ShowcaseProperty, onShowCaseCompleted: () -> Unit) {
139152 modifier = Modifier
140153 .fillMaxSize()
141154 .pointerInput(targets) {
142- detectTapGestures { tapOffset ->
143- if (targetRect.contains(tapOffset) ) {
155+ if (isAutomaticShowcase) {
156+ Timer ( true ).schedule(targets.showcaseDelay ) {
144157 onShowCaseCompleted()
145158 }
159+ } else {
160+ detectTapGestures { tapOffset ->
161+ if (targetRect.contains(tapOffset)) {
162+ onShowCaseCompleted()
163+ }
164+ }
146165 }
147166 }
148167 .graphicsLayer(alpha = 0.99f )
@@ -153,7 +172,7 @@ fun IntroShowCase(targets: ShowcaseProperty, onShowCaseCompleted: () -> Unit) {
153172 */
154173 ShowcaseType .SIMPLE_ROUNDED -> {
155174 drawCircle(
156- color = Color .Black .copy(alpha = 0.8f ),
175+ color = Color .Black .copy(alpha = targets.blurOpacity ),
157176 radius = size.maxDimension,
158177 alpha = 0.9f
159178 )
@@ -169,7 +188,7 @@ fun IntroShowCase(targets: ShowcaseProperty, onShowCaseCompleted: () -> Unit) {
169188 */
170189 ShowcaseType .SIMPLE_RECTANGLE -> {
171190 drawRect(
172- Color .Black .copy(alpha = 0.8f ),
191+ Color .Black .copy(alpha = targets.blurOpacity ),
173192 size = Size (size.width + 40f , size.height + 40f ),
174193 style = Fill ,
175194 )
@@ -189,7 +208,7 @@ fun IntroShowCase(targets: ShowcaseProperty, onShowCaseCompleted: () -> Unit) {
189208 color = Color .Black ,
190209 center = outerOffset,
191210 radius = outerRadius * outerAnimaTable.value,
192- alpha = 0.9f
211+ alpha = targets.blurOpacity
193212 )
194213 // draw circle with animation
195214 dys.forEach { dy ->
@@ -212,7 +231,7 @@ fun IntroShowCase(targets: ShowcaseProperty, onShowCaseCompleted: () -> Unit) {
212231 */
213232 ShowcaseType .ANIMATED_RECTANGLE -> {
214233 drawRect(
215- Color .Black .copy(alpha = 0.8f ),
234+ Color .Black .copy(alpha = targets.blurOpacity ),
216235 size = Size (size.width + 40f , size.height + 40f ),
217236 style = Fill ,
218237 )
@@ -225,7 +244,7 @@ fun IntroShowCase(targets: ShowcaseProperty, onShowCaseCompleted: () -> Unit) {
225244 )
226245 dys.forEach { dy ->
227246 drawRect(
228- color = Color .White .copy(alpha = 0.8f ),
247+ color = Color .White .copy(alpha = targets.blurOpacity ),
229248 size = Size (rectSize.width * dy * 2 , rectSize.height * dy * 2 ),
230249 topLeft = Offset (xOffset - 12 , yOffset - 12 ),
231250 alpha = 1 - dy
0 commit comments