Skip to content

Commit e7cc4c7

Browse files
committed
Added Dokka documentation
1 parent 9cf4d8e commit e7cc4c7

2 files changed

Lines changed: 111 additions & 1 deletion

File tree

composeextensions/src/main/kotlin/sco/carlukesoftware/composeextensions/Modifiers.kt

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ fun Modifier.innerShadow(
191191
}
192192
}
193193

194+
/**
195+
* Applies a fade effect over the content, drawing a gradient from an initial color to a final color.
196+
* This can be used to create effects like text fading into the background.
197+
*
198+
* @param initialColor The color at the start of the gradient. Defaults to [Color.Transparent].
199+
* @param fadeToColor The color at the end of the gradient. Defaults to [Color.White].
200+
* @param verticalFade If true, the gradient will be vertical (top to bottom). If false, it will be horizontal (left to right). Defaults to true.
201+
* @return A [Modifier] that draws a gradient over the content.
202+
*/
194203
fun Modifier.fadeOut(
195204
initialColor: Color = Color.Transparent,
196205
fadeToColor: Color = Color.White,
@@ -203,6 +212,21 @@ fun Modifier.fadeOut(
203212
)
204213
}
205214

215+
/**
216+
* Applies a glowing effect around the composable.
217+
*
218+
* This modifier draws a shadow layer behind the composable, creating a "glow" effect.
219+
* The shape of the glow will match the rounded rectangle shape of the composable.
220+
*
221+
* @param glowingColor The color of the glow.
222+
* @param containerColor The color of the container itself. This is drawn to provide a surface for the shadow to appear behind. Defaults to [Color.White].
223+
* @param cornerRadius The corner radius for the rounded rectangle shape of both the container and the glow. Defaults to 0.dp for a sharp-cornered rectangle.
224+
* @param glowingRadius The blur radius of the glow. A larger value will create a more spread-out and softer glow. Defaults to 20.dp.
225+
* @param glowAlpha The alpha transparency of the glow. Defaults to 0.8f.
226+
* @param offsetX The horizontal offset of the glow. A positive value shifts the glow to the right, a negative value to the left. Defaults to 0.dp.
227+
* @param offsetY The vertical offset of the glow. A positive value shifts the glow downwards, a negative value upwards. Defaults to 0.dp.
228+
* @return A [Modifier] that applies the glow effect.
229+
*/
206230
fun Modifier.glow(
207231
glowingColor: Color,
208232
containerColor: Color = Color.White,
@@ -232,6 +256,21 @@ fun Modifier.glow(
232256
}
233257

234258

259+
/**
260+
* Creates a parallax effect on a composable as the user scrolls.
261+
* The composable's vertical position is adjusted based on the `scrollState`.
262+
*
263+
* This modifier is useful for creating depth in a scrollable layout, where some elements
264+
* (like a background image) move at a different speed than the foreground content.
265+
*
266+
* @param scrollState The [ScrollState] of the scrollable container. The parallax effect
267+
* is driven by changes in this state's value.
268+
* @param rate A factor to control the speed of the parallax effect. A higher rate results
269+
* in a slower movement of the composable. A rate of 0 will cause the composable
270+
* to move at the same speed as the scroll, while a negative rate is not recommended.
271+
* The vertical offset is calculated as `scrollState.value / rate`.
272+
* @return A [Modifier] that applies the parallax layout behavior.
273+
*/
235274
fun Modifier.parallaxLayout(scrollState: ScrollState, rate: Int) =
236275
layout { measurable, constraints ->
237276
val placeable = measurable.measure(constraints = constraints)
@@ -247,6 +286,14 @@ fun Modifier.parallaxLayout(scrollState: ScrollState, rate: Int) =
247286

248287
}
249288

289+
/**
290+
* Applies a shimmering effect to the composable. This is often used to indicate a loading state.
291+
* The shimmer is a linear gradient that animates across the composable.
292+
*
293+
* This overload uses a predefined set of grey colors for the shimmer effect.
294+
*
295+
* @return A [Modifier] that adds the shimmer effect.
296+
*/
250297
fun Modifier.shimmerEffect(): Modifier = composed {
251298
var size by remember {
252299
mutableStateOf(IntSize.Zero)
@@ -279,6 +326,27 @@ fun Modifier.shimmerEffect(): Modifier = composed {
279326
}
280327
}
281328

329+
/**
330+
* Applies a shimmering effect to a composable, typically used for loading placeholders.
331+
*
332+
* This modifier creates a shimmering animation by applying a linear gradient that moves across the composable.
333+
* The animation is an infinite loop, giving the appearance of a continuous shimmer.
334+
*
335+
* The gradient consists of three colors by default (`0xFFB8B5B5`, `0xFF6D6868`, `0xFFB8B5B5`)
336+
* to create a highlight effect that sweeps across the component.
337+
*
338+
* @return A [Modifier] that applies the shimmer effect.
339+
*
340+
* @sample
341+
* ```
342+
* Box(
343+
* modifier = Modifier
344+
* .size(100.dp, 20.dp)
345+
* .clip(RoundedCornerShape(4.dp))
346+
* .shimmerEffect()
347+
* )
348+
* ```
349+
*/
282350
fun Modifier.shimmerEffect(
283351
baseColor: Color = Color.LightGray
284352
): Modifier = composed {

composeextensions/src/main/kotlin/sco/carlukesoftware/composeextensions/utils/GetString.kt

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,53 @@ import androidx.annotation.StringRes
55
import androidx.compose.runtime.Composable
66
import androidx.compose.ui.res.stringResource
77

8+
/**
9+
* A sealed interface for representing a string that can be retrieved in different ways.
10+
* This is useful for decoupling UI components from how strings are sourced, whether they
11+
* come from a remote API (`ApiString`) or from local Android string resources (`StringResource`).
12+
*
13+
* It provides methods to resolve the string value both within a Composable context and
14+
* outside of it (using an Android `Context`).
15+
*
16+
* Example Usage:
17+
* ```
18+
* // In a ViewModel
19+
* val title: GetString = GetString.StringResource(R.string.my_title)
20+
* val subtitle: GetString = GetString.ApiString("Live Data from API")
21+
*
22+
* // In a Composable
23+
* @Composable
24+
* fun MyScreen(title: GetString, subtitle: GetString) {
25+
* Column {
26+
* Text(text = title.asString()) // Uses stringResource()
27+
* Text(text = subtitle.asString()) // Uses the raw string
28+
* }
29+
* }
30+
*
31+
* // Outside of Compose (e.g., in a Service or BroadcastReceiver)
32+
* fun showNotification(context: Context, title: GetString) {
33+
* val notificationText = title.asString(context) // Uses context.getString()
34+
* // ... build and show notification
35+
* }
36+
* ```
37+
*/
838
sealed interface GetString {
939

40+
/**
41+
* Represents a string that is obtained from an external source, like a network API.
42+
* This class wraps a raw [String] value, distinguishing it from a local Android string resource.
43+
*
44+
* @property value The literal string content.
45+
*/
1046
data class ApiString(val value: String): GetString
1147

48+
/**
49+
* Represents a string that can be retrieved from Android string resources.
50+
* This is useful for providing localized strings within the application.
51+
*
52+
* @param resourceId The ID of the string resource (e.g., `R.string.my_string`).
53+
* @param args The optional format arguments to be used for substitution in the string resource.
54+
*/
1255
class StringResource(@StringRes val resourceId: Int, vararg val args: Any): GetString
1356

1457
@Composable
@@ -35,4 +78,3 @@ sealed interface GetString {
3578
}
3679
}
3780
}
38-

0 commit comments

Comments
 (0)