diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseContextExample.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseContextExample.kt index a609dc3..b22e67b 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseContextExample.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseContextExample.kt @@ -2,10 +2,7 @@ package xyz.junerver.composehooks.example import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -15,6 +12,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import xyz.junerver.compose.hooks.* +import xyz.junerver.composehooks.example.request.DividerSpacer import xyz.junerver.composehooks.ui.component.TButton /* @@ -60,7 +58,7 @@ fun UseContextExample() { Text( "Use `useContext` to easily pass states or events to child components, avoiding layer-by-layer transmission between components" ) - HorizontalDivider(modifier = Modifier.fillMaxWidth().padding(top = 20.dp, bottom = 20.dp)) + DividerSpacer() Text(text = "ChileOne:") ChildOne() Spacer(modifier = Modifier.height(20.dp)) diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseCountdownExample.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseCountdownExample.kt index 16001cc..a587895 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseCountdownExample.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseCountdownExample.kt @@ -1,23 +1,19 @@ package xyz.junerver.composehooks.example import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue -import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp import kotlin.time.Duration.Companion.seconds import kotlinx.datetime.LocalDateTime import kotlinx.datetime.TimeZone import kotlinx.datetime.toInstant import xyz.junerver.compose.hooks.useCountdown import xyz.junerver.compose.hooks.useState +import xyz.junerver.composehooks.example.request.DividerSpacer /* Description: @@ -32,7 +28,7 @@ fun UseCountdownExample() { Surface { Column { SimpleOne() - HorizontalDivider(modifier = Modifier.fillMaxWidth().padding(top = 20.dp, bottom = 20.dp)) + DividerSpacer() SimpleTwo() } } diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseEventExample.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseEventExample.kt index 3f181a3..d0111af 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseEventExample.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseEventExample.kt @@ -2,16 +2,14 @@ package xyz.junerver.composehooks.example import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier import kotlin.random.Random import xyz.junerver.compose.hooks.useEventPublish import xyz.junerver.compose.hooks.useEventSubscribe import xyz.junerver.compose.hooks.useGetState +import xyz.junerver.composehooks.example.request.DividerSpacer import xyz.junerver.composehooks.ui.component.TButton /* @@ -58,6 +56,6 @@ fun SubComponent(index: Int) { refresh() } } - HorizontalDivider(modifier = Modifier.fillMaxWidth()) + DividerSpacer() } } diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseStateExample.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseStateExample.kt index 81cff26..21619ba 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseStateExample.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/UseStateExample.kt @@ -2,10 +2,8 @@ package xyz.junerver.composehooks.example import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -24,6 +22,7 @@ import xyz.junerver.compose.hooks.tuple import xyz.junerver.compose.hooks.useGetState import xyz.junerver.compose.hooks.useLatestRef import xyz.junerver.compose.hooks.useState +import xyz.junerver.composehooks.example.request.DividerSpacer import xyz.junerver.composehooks.ui.component.TButton /* @@ -49,21 +48,17 @@ fun UseStateExample() { Text(text = "this is a simple controlled component:") OutlinedTextField(value = state, onValueChange = setState) Text(text = "input:$state") - HorizontalDivider(modifier = Modifier.fillMaxWidth().padding(top = 20.dp)) + DividerSpacer() Text( "Don't destructure `useState`, it will cause the following problems:", modifier = Modifier.padding(top = 20.dp, bottom = 20.dp) ) UseStateQuestionOne() Spacer(modifier = Modifier.height(20.dp)) - HorizontalDivider( - modifier = Modifier - .fillMaxWidth() - .padding(20.dp) - ) + DividerSpacer() Spacer(modifier = Modifier.height(20.dp)) UseStateQuestionTwo() - HorizontalDivider(modifier = Modifier.fillMaxWidth().padding(top = 20.dp, bottom = 20.dp)) + DividerSpacer() Text("Demonstrates how to avoid closure problems, please see the sample code") HowToAvoidClosureProblems() } diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Auto&Manual.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Auto&Manual.kt index 4be85e4..13c7a3f 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Auto&Manual.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Auto&Manual.kt @@ -3,11 +3,9 @@ package xyz.junerver.composehooks.example.request import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -38,7 +36,7 @@ fun AutoManual() { ) { Auto() Spacer(modifier = Modifier.height(10.dp)) - HorizontalDivider(modifier = Modifier.fillMaxWidth()) + DividerSpacer() Manual() } } diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cache&SWR.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cache&SWR.kt index a5479d0..cebcca2 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cache&SWR.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cache&SWR.kt @@ -2,17 +2,11 @@ package xyz.junerver.composehooks.example.request import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.dp import kotlin.coroutines.coroutineContext import kotlin.random.Random import kotlin.time.Duration.Companion.seconds @@ -56,8 +50,7 @@ fun Cache() { Surface { Column { TestSWR() - Spacer(modifier = Modifier.height(20.dp)) - HorizontalDivider(modifier = Modifier.fillMaxWidth()) + DividerSpacer() TestStaleTime() } } @@ -73,7 +66,7 @@ private fun TestSWR() { if (isVisible.value) { SWR() } - HorizontalDivider(modifier = Modifier.fillMaxWidth()) + DividerSpacer() if (isVisible.value) { SWR(true) } @@ -98,7 +91,7 @@ private fun SWR(useCache: Boolean = false) { ) val data by dataState val loading by loadingState - Column(modifier = Modifier.height(210.dp)) { + Column { Text(text = "cache: $useCache", color = Color.Red) Text(text = "Background loading: $loading") if (data.asBoolean()) { @@ -143,7 +136,7 @@ private fun StaleTime(cacheKey: String) { ) val data by dataState val loading by loadingState - Column(modifier = Modifier.height(210.dp)) { + Column { Text(text = "statleTime: 5s", color = Color.Red) Text(text = "Background loading: $loading") if (data.asBoolean()) { diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cancel.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cancel.kt index a971bb5..68c71b1 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cancel.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Cancel.kt @@ -2,13 +2,10 @@ package xyz.junerver.composehooks.example.request import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier import xyz.junerver.compose.hooks.invoke import xyz.junerver.compose.hooks.userequest.useRequest import xyz.junerver.compose.hooks.utils.asBoolean @@ -45,7 +42,7 @@ fun Cancel() { cancel() } } - HorizontalDivider(modifier = Modifier.fillMaxWidth()) + DividerSpacer() if (loading) { Text(text = "Loading ...") diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Ready.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Ready.kt index 5c24056..f72a420 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Ready.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/Ready.kt @@ -2,9 +2,7 @@ package xyz.junerver.composehooks.example.request import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -60,7 +58,7 @@ fun Ready() { Text(text = "$userInfo".substring(0..100)) } Spacer(modifier = Modifier.height(30.dp)) - HorizontalDivider(modifier = Modifier.fillMaxWidth()) + DividerSpacer() if (repoLoading) { Text(text = "repo loading ...") } else if (repoInfo.asBoolean()) { diff --git a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/component.kt b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/component.kt index cc4a38b..b620278 100644 --- a/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/component.kt +++ b/app/src/commonMain/kotlin/xyz/junerver/composehooks/example/request/component.kt @@ -1,9 +1,9 @@ package xyz.junerver.composehooks.example.request import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding import androidx.compose.material3.HorizontalDivider import androidx.compose.material3.Text import androidx.compose.runtime.Composable @@ -12,6 +12,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import kotlin.time.Duration.Companion.seconds import xyz.junerver.compose.hooks.* +import xyz.junerver.compose.hooks.userequest.RequestOptions import xyz.junerver.compose.hooks.userequest.useRequest import xyz.junerver.compose.hooks.utils.asBoolean import xyz.junerver.composehooks.net.NetApi @@ -27,10 +28,7 @@ import xyz.junerver.composehooks.ui.component.TButton @Composable fun DividerSpacer() { - Column { - HorizontalDivider(modifier = Modifier.fillMaxWidth()) - Spacer(modifier = Modifier.height(20.dp)) - } + HorizontalDivider(modifier = Modifier.fillMaxWidth().padding(top = 20.dp, bottom = 20.dp)) } enum class OptionFunc { @@ -61,9 +59,9 @@ fun SubComponent(label: String, isUsed: Boolean = false, optionFunc: OptionFunc) when (optionFunc) { OptionFunc.LoadingDelay -> run { /** - * 当你配置了[loadingDelay],如果请求在这个时间之内返回就不会引起loading的变化, + * 当你配置了[RequestOptions.loadingDelay],如果请求在这个时间之内返回就不会引起loading的变化, * 这可以避免闪烁,适用于接口较为快速返回的场景。 - * When you configure [loadingDelay], if the request response within this duration, + * When you configure [RequestOptions.loadingDelay], if the request response within this duration, * it will not cause loading state changes. * This can avoid flickering and is suitable for scenarios * where the interface returns quickly. @@ -97,7 +95,7 @@ fun SubComponent(label: String, isUsed: Boolean = false, optionFunc: OptionFunc) val userInfo by userInfoState val loading by loadingState Column(modifier = Modifier.height(100.dp)) { - Text(text = "$label:$isUsed") + Text(text = "$label:$isUsed${if (isUsed) " $label wait 3seconds" else ""}") if (loading) { Text(text = "Loading ...") } else if (userInfo.asBoolean()) {