Skip to content

Commit 72e04ba

Browse files
committed
Merge branch 'main' into latest
2 parents f7f7cfe + 2db5704 commit 72e04ba

File tree

23 files changed

+696
-77
lines changed

23 files changed

+696
-77
lines changed

.github/workflows/sync_main_latest.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121

2222
- name: Create pull request
2323
id: cpr
24-
uses: peter-evans/create-pull-request@v6
24+
uses: peter-evans/create-pull-request@v7
2525
with:
2626
token: ${{ secrets.PAT }}
2727
commit-message: 🤖 Sync main to latest

.github/workflows/update_deps.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: ./gradlew versionCatalogUpdate
2020
- name: Create pull request
2121
id: cpr
22-
uses: peter-evans/create-pull-request@v6
22+
uses: peter-evans/create-pull-request@v7
2323
with:
2424
token: ${{ secrets.PAT }}
2525
commit-message: 🤖 Update Dependencies

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ plugins {
55
alias(libs.plugins.android.application) apply false
66
alias(libs.plugins.android.library) apply false
77
alias(libs.plugins.kotlin.android) apply false
8-
alias(libs.plugins.kapt) apply false
8+
alias(libs.plugins.ksp) apply false
99
alias(libs.plugins.hilt) apply false
1010
alias(libs.plugins.kotlin.parcelize) apply false
1111
alias(libs.plugins.compose.compiler) apply false

compose/snippets/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
plugins {
1818
alias(libs.plugins.android.application)
1919
alias(libs.plugins.kotlin.android)
20-
alias(libs.plugins.kapt)
20+
alias(libs.plugins.ksp)
2121
alias(libs.plugins.hilt)
2222
alias(libs.plugins.kotlin.parcelize)
2323
alias(libs.plugins.compose.compiler)
@@ -144,7 +144,9 @@ dependencies {
144144
implementation(libs.googlemaps.maps)
145145

146146
implementation(libs.hilt.android)
147-
kapt(libs.hilt.compiler)
147+
implementation(libs.glide.compose)
148+
149+
ksp(libs.hilt.compiler)
148150

149151
testImplementation(libs.junit)
150152

compose/snippets/src/main/java/com/example/compose/snippets/animations/AnimationSnippets.kt

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ import androidx.compose.ui.unit.Dp
109109
import androidx.compose.ui.unit.IntSize
110110
import androidx.compose.ui.unit.dp
111111
import com.example.compose.snippets.R
112+
import java.text.BreakIterator
113+
import java.text.StringCharacterIterator
114+
import kotlinx.coroutines.delay
112115

113116
/*
114117
* Copyright 2023 The Android Open Source Project
@@ -820,3 +823,39 @@ private fun Expanded() {
820823
@Composable
821824
private fun ContentIcon() {
822825
}
826+
827+
// [START android_compose_animations_char_by_char]
828+
@Composable
829+
private fun AnimatedText() {
830+
val text = "This text animates as though it is being typed \uD83E\uDDDE\u200D\uFE0F \uD83D\uDD10 \uD83D\uDC69\u200D\uFE0F\u200D\uD83D\uDC68 \uD83D\uDC74\uD83C\uDFFD"
831+
832+
// Use BreakIterator as it correctly iterates over characters regardless of how they are
833+
// stored, for example, some emojis are made up of multiple characters.
834+
// You don't want to break up an emoji as it animates, so using BreakIterator will ensure
835+
// this is correctly handled!
836+
val breakIterator = remember(text) { BreakIterator.getCharacterInstance() }
837+
838+
// Define how many milliseconds between each character should pause for. This will create the
839+
// illusion of an animation, as we delay the job after each character is iterated on.
840+
val typingDelayInMs = 50L
841+
842+
var substringText by remember {
843+
mutableStateOf("")
844+
}
845+
LaunchedEffect(text) {
846+
// Initial start delay of the typing animation
847+
delay(1000)
848+
breakIterator.text = StringCharacterIterator(text)
849+
850+
var nextIndex = breakIterator.next()
851+
// Iterate over the string, by index boundary
852+
while (nextIndex != BreakIterator.DONE) {
853+
substringText = text.subSequence(0, nextIndex).toString()
854+
// Go to the next logical character boundary
855+
nextIndex = breakIterator.next()
856+
delay(typingDelayInMs)
857+
}
858+
}
859+
Text(substringText)
860+
// [END android_compose_animations_char_by_char]
861+
}

compose/snippets/src/main/java/com/example/compose/snippets/images/LoadingImagesSnippets.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import androidx.compose.ui.res.painterResource
2222
import androidx.compose.ui.res.stringResource
2323
import androidx.compose.ui.tooling.preview.Preview
2424
import coil.compose.AsyncImage
25+
import com.bumptech.glide.integration.compose.ExperimentalGlideComposeApi
26+
import com.bumptech.glide.integration.compose.GlideImage
2527
import com.example.compose.snippets.R
2628

2729
/*
@@ -53,11 +55,23 @@ fun LoadingImageFromDisk() {
5355

5456
@Preview
5557
@Composable
56-
fun LoadingImageFromInternet() {
58+
fun LoadingImageFromInternetCoil() {
5759
// [START android_compose_images_load_internet_coil]
5860
AsyncImage(
5961
model = "https://example.com/image.jpg",
6062
contentDescription = "Translated description of what the image contains"
6163
)
6264
// [END android_compose_images_load_internet_coil]
6365
}
66+
67+
@OptIn(ExperimentalGlideComposeApi::class)
68+
@Preview
69+
@Composable
70+
fun LoadingImageFromInternetGlide() {
71+
// [START android_compose_images_load_internet_glide]
72+
GlideImage(
73+
model = "https://example.com/image.jpg",
74+
contentDescription = "Translated description of what the image contains"
75+
)
76+
// [END android_compose_images_load_internet_glide]
77+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*
2+
* Copyright 2024 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.example.compose.snippets.images
18+
19+
import androidx.compose.foundation.Image
20+
import androidx.compose.foundation.ScrollState
21+
import androidx.compose.foundation.background
22+
import androidx.compose.foundation.layout.Column
23+
import androidx.compose.foundation.layout.fillMaxWidth
24+
import androidx.compose.foundation.layout.padding
25+
import androidx.compose.foundation.rememberScrollState
26+
import androidx.compose.foundation.verticalScroll
27+
import androidx.compose.material3.Text
28+
import androidx.compose.runtime.Composable
29+
import androidx.compose.ui.Modifier
30+
import androidx.compose.ui.graphics.Color
31+
import androidx.compose.ui.layout.ContentScale
32+
import androidx.compose.ui.layout.layout
33+
import androidx.compose.ui.res.painterResource
34+
import androidx.compose.ui.res.stringResource
35+
import androidx.compose.ui.unit.dp
36+
import com.example.compose.snippets.R
37+
38+
// [START android_compose_images_parallax]
39+
@Composable
40+
fun ParallaxEffect() {
41+
fun Modifier.parallaxLayoutModifier(scrollState: ScrollState, rate: Int) =
42+
layout { measurable, constraints ->
43+
val placeable = measurable.measure(constraints)
44+
val height = if (rate > 0) scrollState.value / rate else scrollState.value
45+
layout(placeable.width, placeable.height) {
46+
placeable.place(0, height)
47+
}
48+
}
49+
50+
val scrollState = rememberScrollState()
51+
Column(
52+
modifier = Modifier
53+
.fillMaxWidth()
54+
.verticalScroll(scrollState),
55+
) {
56+
57+
Image(
58+
painterResource(id = R.drawable.cupcake),
59+
contentDescription = "Android logo",
60+
contentScale = ContentScale.Fit,
61+
// Reduce scrolling rate by half.
62+
modifier = Modifier.parallaxLayoutModifier(scrollState, 2)
63+
)
64+
65+
Text(
66+
text = stringResource(R.string.detail_placeholder),
67+
modifier = Modifier
68+
.background(Color.White)
69+
.padding(horizontal = 8.dp),
70+
71+
)
72+
}
73+
}
74+
// [END android_compose_images_parallax]

compose/snippets/src/main/java/com/example/compose/snippets/interop/ComposeWithOtherLibraries.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ private object StreamData {
162162
}
163163
}
164164

165-
private object HiltExample3 {
165+
object HiltExample3 {
166166
// [START android_compose_libraries_hilt_3]
167167
@HiltViewModel
168168
class MyViewModel @Inject constructor(
@@ -180,7 +180,7 @@ private object HiltExample3 {
180180
interface ExampleRepository
181181
}
182182

183-
private object HiltViewModel {
183+
object HiltViewModel {
184184
@HiltViewModel
185185
class MyViewModel @Inject constructor() : ViewModel() { /* ... */ }
186186
// [START android_compose_libraries_hilt_viewmodel]
@@ -207,7 +207,7 @@ private object HiltViewModel {
207207
}
208208
}
209209

210-
private object HiltViewModelBackStack {
210+
object HiltViewModelBackStack {
211211
@HiltViewModel
212212
class MyViewModel @Inject constructor() : ViewModel() { /* ... */ }
213213

@@ -273,7 +273,7 @@ private object MapsExample {
273273
cameraPositionState = cameraPositionState
274274
) {
275275
Marker(
276-
state = MarkerState(position = singapore),
276+
state = remember { MarkerState(position = singapore) },
277277
title = "Singapore",
278278
snippet = "Marker in Singapore"
279279
)

0 commit comments

Comments
 (0)