File tree Expand file tree Collapse file tree 1 file changed +25
-1
lines changed
reveal-core/src/main/kotlin/com/svenjacobs/reveal Expand file tree Collapse file tree 1 file changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -62,11 +62,35 @@ public class RevealState internal constructor(
62
62
/* *
63
63
* Reveals revealable with given [key]
64
64
*
65
+ * Might throw [IllegalArgumentException] if the revealable item is not known to Reveal. This
66
+ * might happen if for example the item is in a lazy container and is currently not part of the
67
+ * visible area. It is the duty of the developer to ensure that a revealable item is currently
68
+ * visible (known to Reveal) before calling this function. Additionally [containsRevealable] or
69
+ * [revealableKeys] can be used to ensure this.
70
+ *
71
+ * @see tryReveal
65
72
* @see containsRevealable
73
+ * @see revealableKeys
66
74
* @throws IllegalArgumentException if revealable with given key was not found
67
75
*/
68
76
public suspend fun reveal (key : Key ) {
69
- require(revealables.containsKey(key)) { " Revealable with key \" $key \" not found" }
77
+ require(containsRevealable(key)) { " Revealable with key \" $key \" not found" }
78
+ internalReveal(key)
79
+ }
80
+
81
+ /* *
82
+ * Like [reveal] but doesn't throw exception if revealable was not found.
83
+ * Instead returns `false`.
84
+ *
85
+ * @see reveal
86
+ */
87
+ public suspend fun tryReveal (key : Key ): Boolean {
88
+ if (! containsRevealable(key)) return false
89
+ internalReveal(key)
90
+ return true
91
+ }
92
+
93
+ private suspend fun internalReveal (key : Key ) {
70
94
mutex.withLock {
71
95
previousRevealable = currentRevealable
72
96
currentRevealable = revealables[key]
You can’t perform that action at this time.
0 commit comments