diff --git a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/BaseRevealTest.kt b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/BaseRevealTest.kt index 2299967..20f474e 100644 --- a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/BaseRevealTest.kt +++ b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/BaseRevealTest.kt @@ -1,19 +1,25 @@ -package com.svenjacobs.reveal +package com.svenjacobs.reveal.android.tests import androidx.compose.material3.Text import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.test.junit4.ComposeContentTestRule import androidx.compose.ui.test.junit4.createComposeRule +import com.svenjacobs.reveal.OnClickListener +import com.svenjacobs.reveal.Reveal +import com.svenjacobs.reveal.RevealCanvas +import com.svenjacobs.reveal.RevealState +import com.svenjacobs.reveal.rememberRevealCanvasState +import com.svenjacobs.reveal.rememberRevealState import kotlinx.coroutines.CoroutineScope import org.junit.Rule -public abstract class BaseRevealTest { +abstract class BaseRevealTest { internal enum class Keys { Key1, Key2, Key3 } @get:Rule - public val composeTestRule: ComposeContentTestRule = createComposeRule() + val composeTestRule: ComposeContentTestRule = createComposeRule() internal fun test( onRevealableClick: OnClickListener = {}, diff --git a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealOverlayTest.kt b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealOverlayTest.kt index b34bf63..f186dbd 100644 --- a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealOverlayTest.kt +++ b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealOverlayTest.kt @@ -1,4 +1,4 @@ -package com.svenjacobs.reveal +package com.svenjacobs.reveal.android.tests import androidx.compose.ui.test.onNodeWithText import junit.framework.TestCase.assertEquals @@ -7,10 +7,10 @@ import junit.framework.TestCase.assertTrue import kotlinx.coroutines.launch import org.junit.Test -public class RevealOverlayTest : BaseRevealTest() { +class RevealOverlayTest : BaseRevealTest() { @Test - public fun revealShowsOverlay() { + fun revealShowsOverlay() { test { testRule, revealState, scope -> scope.launch { revealState.reveal(Keys.Key1) } @@ -33,7 +33,7 @@ public class RevealOverlayTest : BaseRevealTest() { } @Test - public fun hideHidesOverlay() { + fun hideHidesOverlay() { test { testRule, revealState, scope -> scope.launch { revealState.reveal(Keys.Key1) } diff --git a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealStateTest.kt b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealStateTest.kt index eb2a42f..fe9c24d 100644 --- a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealStateTest.kt +++ b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealStateTest.kt @@ -1,13 +1,13 @@ -package com.svenjacobs.reveal +package com.svenjacobs.reveal.android.tests import org.junit.Assert.assertFalse import org.junit.Assert.assertTrue import org.junit.Test -public class RevealStateTest : BaseRevealTest() { +class RevealStateTest : BaseRevealTest() { @Test - public fun stateContainsKeys() { + fun stateContainsKeys() { test { _, revealState, _ -> assertTrue(revealState.revealableKeys.contains(Keys.Key1)) assertTrue(revealState.revealableKeys.contains(Keys.Key2)) diff --git a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealTest.kt b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealTest.kt index 8bd0efe..62c2e62 100644 --- a/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealTest.kt +++ b/android-tests/src/androidTest/kotlin/com/svenjacobs/reveal/android/tests/RevealTest.kt @@ -1,16 +1,17 @@ -package com.svenjacobs.reveal +package com.svenjacobs.reveal.android.tests import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick +import com.svenjacobs.reveal.Key import junit.framework.TestCase.assertEquals import kotlinx.coroutines.launch import org.junit.Test -public class RevealTest : BaseRevealTest() { +class RevealTest : BaseRevealTest() { @Test - public fun clickCallsOnRevealableClick() { + fun clickCallsOnRevealableClick() { var onRevealableClickKey: Key? = null test( @@ -25,7 +26,7 @@ public class RevealTest : BaseRevealTest() { } @Test - public fun clickCallsOnOverlayClick() { + fun clickCallsOnOverlayClick() { var onOverlayClickKey: Key? = null test( diff --git a/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt b/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt index 3602ade..6d71705 100644 --- a/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt +++ b/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt @@ -116,8 +116,8 @@ public fun Modifier.revealable( ): Modifier = this.then( Modifier .onGloballyPositioned { layoutCoordinates -> - for (key in keys) { - state.putRevealable( + keys.forEach { key -> + state.addRevealable( Revealable( key = key, shape = shape, @@ -134,9 +134,7 @@ public fun Modifier.revealable( .composed { DisposableEffect(Unit) { onDispose { - for (key in keys) { - state.removeRevealable(key) - } + keys.forEach(state::removeRevealable) } } this diff --git a/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/RevealState.kt b/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/RevealState.kt index d01f205..2bdaa41 100644 --- a/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/RevealState.kt +++ b/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/RevealState.kt @@ -134,7 +134,7 @@ public class RevealState internal constructor( * * @see RevealScope.revealable */ - public fun putRevealable(revealable: Revealable) { + public fun addRevealable(revealable: Revealable) { revealables[revealable.key] = revealable if (!didRestoreCurrentRevealable && restoreCurrentRevealableKey == revealable.key) { @@ -143,6 +143,15 @@ public class RevealState internal constructor( } } + /** + * @see addRevealable + */ + @Deprecated( + message = "Use addRevealable()", + replaceWith = ReplaceWith("addRevealable(revealable)"), + ) + public fun putRevealable(revealable: Revealable): Unit = addRevealable(revealable) + /** * Removes a [Revealable] from this state. *