From d31d800b2c585bffe83284a7d489358dcf134564 Mon Sep 17 00:00:00 2001 From: Sven Jacobs Date: Fri, 8 Mar 2024 20:21:36 +0100 Subject: [PATCH 1/3] chore: rename putRevealable() to addRevealable() --- .../kotlin/com/svenjacobs/reveal/Modifiers.kt | 2 +- .../kotlin/com/svenjacobs/reveal/RevealState.kt | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) 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..a3674b1 100644 --- a/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt +++ b/reveal-core/src/commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt @@ -117,7 +117,7 @@ public fun Modifier.revealable( Modifier .onGloballyPositioned { layoutCoordinates -> for (key in keys) { - state.putRevealable( + state.addRevealable( Revealable( key = key, shape = shape, 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. * From 374d59825df8da3f9c0bed0f199fd849dbad0cf7 Mon Sep 17 00:00:00 2001 From: Sven Jacobs Date: Fri, 8 Mar 2024 20:30:06 +0100 Subject: [PATCH 2/3] chore: minor code changes --- .../commonMain/kotlin/com/svenjacobs/reveal/Modifiers.kt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) 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 a3674b1..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,7 +116,7 @@ public fun Modifier.revealable( ): Modifier = this.then( Modifier .onGloballyPositioned { layoutCoordinates -> - for (key in keys) { + keys.forEach { key -> state.addRevealable( Revealable( key = key, @@ -134,9 +134,7 @@ public fun Modifier.revealable( .composed { DisposableEffect(Unit) { onDispose { - for (key in keys) { - state.removeRevealable(key) - } + keys.forEach(state::removeRevealable) } } this From f2ca42e90d48c6270770132d75f105673dbb4869 Mon Sep 17 00:00:00 2001 From: Sven Jacobs Date: Fri, 8 Mar 2024 20:49:33 +0100 Subject: [PATCH 3/3] chore: remove redundant visibility modifiers --- .../reveal/android/tests/BaseRevealTest.kt | 12 +++++++++--- .../reveal/android/tests/RevealOverlayTest.kt | 8 ++++---- .../reveal/android/tests/RevealStateTest.kt | 6 +++--- .../svenjacobs/reveal/android/tests/RevealTest.kt | 9 +++++---- 4 files changed, 21 insertions(+), 14 deletions(-) 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(