Skip to content

Commit

Permalink
chore: rename putRevealable() to addRevealable() (#110)
Browse files Browse the repository at this point in the history
* chore: rename putRevealable() to addRevealable()

* chore: minor code changes

* chore: remove redundant visibility modifiers
  • Loading branch information
svenjacobs authored Mar 8, 2024
1 parent b8664f7 commit 50792e9
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -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 = {},
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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) }

Expand All @@ -33,7 +33,7 @@ public class RevealOverlayTest : BaseRevealTest() {
}

@Test
public fun hideHidesOverlay() {
fun hideHidesOverlay() {
test { testRule, revealState, scope ->
scope.launch { revealState.reveal(Keys.Key1) }

Expand Down
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -25,7 +26,7 @@ public class RevealTest : BaseRevealTest() {
}

@Test
public fun clickCallsOnOverlayClick() {
fun clickCallsOnOverlayClick() {
var onOverlayClickKey: Key? = null

test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -134,9 +134,7 @@ public fun Modifier.revealable(
.composed {
DisposableEffect(Unit) {
onDispose {
for (key in keys) {
state.removeRevealable(key)
}
keys.forEach(state::removeRevealable)
}
}
this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.
*
Expand Down

0 comments on commit 50792e9

Please sign in to comment.