-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: yschimke <[email protected]>
- Loading branch information
Showing
23 changed files
with
1,377 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
303 changes: 155 additions & 148 deletions
303
composables/src/main/java/com/google/android/horologist/composables/DatePicker.kt
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
compose-layout/src/main/java/com/google/android/horologist/compose/layout/AppScaffold.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.compose.layout | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.compositionLocalOf | ||
import androidx.compose.ui.Modifier | ||
import androidx.wear.compose.material.Scaffold | ||
import androidx.wear.compose.material.TimeText | ||
import androidx.wear.compose.navigation.SwipeDismissableNavHost | ||
|
||
/** | ||
* An app scaffold, to be used to wrap a [SwipeDismissableNavHost]. | ||
* The [TimeText] will be shown here, but can be customised in either [ScreenScaffold] or | ||
* [PageScaffold]. | ||
* | ||
* Without this, the vanilla [Scaffold] is likely placed on each individual screen and [TimeText] | ||
* moves with the screen, or shown twice when swiping to dimiss. | ||
* | ||
* @param modifier the Scaffold modifier. | ||
* @param timeText the app default time text, defaults to TimeText(). | ||
* @param content the content block. | ||
*/ | ||
@Composable | ||
fun AppScaffold( | ||
modifier: Modifier = Modifier, | ||
timeText: @Composable () -> Unit = { TimeText() }, | ||
content: @Composable BoxScope.() -> Unit, | ||
) { | ||
val scaffoldState = LocalScaffoldState.current.apply { | ||
appTimeText.value = timeText | ||
} | ||
|
||
Scaffold( | ||
modifier = modifier, | ||
timeText = scaffoldState.timeText, | ||
) { | ||
Box(modifier = Modifier.fillMaxSize()) { | ||
content() | ||
} | ||
} | ||
} | ||
|
||
internal val LocalScaffoldState = compositionLocalOf { ScaffoldState() } |
44 changes: 44 additions & 0 deletions
44
compose-layout/src/main/java/com/google/android/horologist/compose/layout/PageScaffold.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.compose.layout | ||
|
||
import androidx.compose.foundation.gestures.ScrollableState | ||
import androidx.compose.foundation.layout.BoxScope | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.wear.compose.material.TimeText | ||
|
||
/** | ||
* Pager Scaffold to place *inside* a single page of HorizontalPager. | ||
* The [TimeText] if set will override the AppScaffold timeText. | ||
* | ||
* @param modifier the Scaffold modifier. | ||
* @param timeText the page specific time text. | ||
* @param scrollState the ScrollableState to show in a default PositionIndicator. | ||
* @param positionIndicator set a non default PositionIndicator or disable with an no-op lambda. | ||
* @param content the content block. | ||
*/ | ||
@Composable | ||
fun PageScaffold( | ||
modifier: Modifier = Modifier, | ||
timeText: (@Composable () -> Unit)? = null, | ||
scrollState: ScrollableState? = null, | ||
positionIndicator: (@Composable () -> Unit)? = null, | ||
content: @Composable BoxScope.() -> Unit, | ||
) { | ||
ScreenScaffold(modifier = modifier, timeText, scrollState, null, positionIndicator, content) | ||
} |
81 changes: 81 additions & 0 deletions
81
compose-layout/src/main/java/com/google/android/horologist/compose/layout/ScaffoldState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.android.horologist.compose.layout | ||
|
||
import androidx.compose.foundation.ScrollState | ||
import androidx.compose.foundation.gestures.ScrollableState | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.ui.Modifier | ||
import androidx.wear.compose.material.TimeText | ||
|
||
internal class ScaffoldState { | ||
fun removeScreenTimeText(key: Any) { | ||
screenContent.removeIf { it.key === key } | ||
} | ||
|
||
fun addScreenTimeText( | ||
key: Any, | ||
timeText: @Composable (() -> Unit)?, | ||
scrollState: ScrollableState?, | ||
) { | ||
screenContent.add(PageContent(key, scrollState, timeText)) | ||
} | ||
|
||
internal val appTimeText: MutableState<(@Composable (() -> Unit))> = | ||
mutableStateOf({ TimeText() }) | ||
internal val screenContent = mutableStateListOf<PageContent>() | ||
|
||
val timeText: @Composable (() -> Unit) | ||
get() = { | ||
val (scrollState, timeText) = currentContent() | ||
|
||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.scrollAway { | ||
scrollState ?: ScrollState(0) | ||
}, | ||
) { | ||
timeText() | ||
} | ||
} | ||
|
||
private fun currentContent(): Pair<ScrollableState?, @Composable (() -> Unit)> { | ||
var resultTimeText: @Composable (() -> Unit)? = null | ||
var resultState: ScrollableState? = null | ||
screenContent.forEach { | ||
if (it.timeText != null) { | ||
resultTimeText = it.timeText | ||
} | ||
if (it.scrollState != null) { | ||
resultState = it.scrollState | ||
} | ||
} | ||
return Pair(resultState, resultTimeText ?: appTimeText.value) | ||
} | ||
|
||
internal data class PageContent( | ||
val key: Any, | ||
val scrollState: ScrollableState? = null, | ||
val timeText: (@Composable () -> Unit)? = null, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.