Skip to content

Commit

Permalink
[Jetsnack] Adding shared elements to Jetsnack 🎉 (#1314)
Browse files Browse the repository at this point in the history
Adding shared elements between Home feed and SnackDetail.

Introduced `SnackSharedElementKey` to create a unique key for the shared
element to match.

Using `Modifier.sharedBounds()` on the Card container, and
`Modifier.sharedElement()` on the Image.

Using `Modifier.sharedBounds()` with `Modifier.animateEnterExit()` on
Text.

The above modifiers require being in an `AnimatedVisibilityScope` and
`SharedTransitionScope`, in order to use the correct scope at the
correct point, we save the scopes in a CompositionLocal and retrieve it
when required.


https://github.com/android/compose-samples/assets/9973046/2d0cf1d9-4ef2-4051-a2e9-b3255d45ac78
  • Loading branch information
riggaroo authored Aug 8, 2024
2 parents ee8e272 + b80e4dd commit d5c7da6
Show file tree
Hide file tree
Showing 36 changed files with 1,369 additions and 738 deletions.
26 changes: 24 additions & 2 deletions .github/workflows/JetNews.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

Expand All @@ -60,11 +64,29 @@ jobs:
~/.gradle/caches/jars-*
~/.gradle/caches/build-cache-*
key: gradle-${{ hashFiles('checksum.txt') }}

- name: AVD cache
uses: actions/cache@v4
id: avd-cache
with:
path: |
~/.android/avd/*
~/.android/adb*
key: avd-${{ matrix.api-level }}
- name: create AVD and generate snapshot for caching
if: steps.avd-cache.outputs.cache-hit != 'true'
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: false
script: echo "Generated AVD snapshot for caching."
- name: Run instrumentation tests
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: ${{ matrix.api-level }}
force-avd-creation: false
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
arch: x86
disable-animations: true
script: ./gradlew connectedCheck --stacktrace
Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/build-sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@ jobs:
- name: Build debug
working-directory: ${{ inputs.path }}
run: ./gradlew assembleDebug --stacktrace

- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run local tests
working-directory: ${{ inputs.path }}
run: ./gradlew testDebug --stacktrace
Expand Down
31 changes: 17 additions & 14 deletions JetLagged/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,22 @@
#####
[versions]
accompanist = "0.34.0"
androidGradlePlugin = "8.5.1"
androidGradlePlugin = "8.5.0"
androidx-activity-compose = "1.9.0"
androidx-appcompat = "1.7.0"
androidx-benchmark = "1.2.4"
androidx-benchmark-junit4 = "1.2.4"
androidx-compose-bom = "2024.06.00"
androidx-compose-material3 = "1.3.0-beta04"
androidx-compose-latest = "1.7.0-beta07"
androidx-compose-material3 = "1.3.0-beta05"
androidx-compose-material3-adaptive = "1.0.0-beta04"
androidx-constraintlayout = "1.0.1"
androidx-constraintlayout = "1.1.0-alpha13"
androidx-core-splashscreen = "1.0.1"
androidx-corektx = "1.13.1"
androidx-glance = "1.1.0"
androidx-lifecycle = "2.8.2"
androidx-lifecycle-compose = "2.6.1"
androidx-lifecycle-runtime-compose = "2.6.1"
androidx-navigation = "2.7.7"
androidx-palette = "1.0.0"
androidx-test = "1.5.0"
Expand Down Expand Up @@ -56,7 +59,7 @@ rome = "1.18.0"
room = "2.6.0"
secrets = "2.0.1"
# @keep
targetSdk = "34"
targetSdk = "33"
version-catalog-update = "0.8.4"

[libraries]
Expand All @@ -71,10 +74,10 @@ androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-benchmark-macrobenchmark = { module = "androidx.benchmark:benchmark-macro", version.ref = "androidx-benchmark" }
androidx-benchmark-macrobenchmark-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-junit4" }
androidx-compose-animation = { module = "androidx.compose.animation:animation" }
androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose-latest" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" }
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-latest"}
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" ,version.ref = "androidx-compose-latest"}
androidx-compose-material = { module = "androidx.compose.material:material" }
androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
Expand All @@ -85,7 +88,7 @@ androidx-compose-material3-adaptive-navigationSuite = { module = "androidx.compo
androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" , version.ref = "androidx-compose-latest"}
androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" }
androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" }
androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" }
Expand All @@ -103,12 +106,12 @@ androidx-glance = { module = "androidx.glance:glance", version.ref = "androidx-g
androidx-glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "androidx-glance" }
androidx-glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "androidx-glance" }
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-runtime ={ module= "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle-compose"}
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle-runtime-compose" }
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle-compose" }
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" }
androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidx-navigation" }
Expand Down
4 changes: 4 additions & 0 deletions JetNews/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ composeCompiler {
enableStrongSkippingMode = true
}

kotlin {
jvmToolchain(17)
}

dependencies {
val composeBom = platform(libs.androidx.compose.bom)
implementation(composeBom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class JetnewsTests {
useUnmergedTree = true
).performClick()
composeTestRule.onNodeWithText("Interests").performClick()
composeTestRule.onNodeWithText("Topics").assertExists()
// TODO - this fails on CI but not locally. (https://github.com/android/compose-samples/issues/1442)
// composeTestRule.waitUntilAtLeastOneExists(hasText("Topics"), 5000L)
}
}
29 changes: 16 additions & 13 deletions JetNews/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ androidx-appcompat = "1.7.0"
androidx-benchmark = "1.2.4"
androidx-benchmark-junit4 = "1.2.4"
androidx-compose-bom = "2024.06.00"
androidx-compose-material3 = "1.3.0-beta01"
androidx-compose-material3-adaptive = "1.0.0-beta01"
androidx-constraintlayout = "1.0.1"
androidx-compose-latest = "1.7.0-beta07"
androidx-compose-material3 = "1.3.0-beta05"
androidx-compose-material3-adaptive = "1.0.0-beta04"
androidx-constraintlayout = "1.1.0-alpha13"
androidx-core-splashscreen = "1.0.1"
androidx-corektx = "1.13.1"
androidx-glance = "1.1.0"
androidx-lifecycle = "2.8.2"
androidx-lifecycle-compose = "2.6.1"
androidx-lifecycle-runtime-compose = "2.6.1"
androidx-navigation = "2.7.7"
androidx-palette = "1.0.0"
androidx-test = "1.5.0"
Expand Down Expand Up @@ -71,10 +74,10 @@ androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-benchmark-macrobenchmark = { module = "androidx.benchmark:benchmark-macro", version.ref = "androidx-benchmark" }
androidx-benchmark-macrobenchmark-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-junit4" }
androidx-compose-animation = { module = "androidx.compose.animation:animation" }
androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose-latest" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" }
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-latest"}
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" ,version.ref = "androidx-compose-latest"}
androidx-compose-material = { module = "androidx.compose.material:material" }
androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
Expand All @@ -85,7 +88,7 @@ androidx-compose-material3-adaptive-navigationSuite = { module = "androidx.compo
androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" , version.ref = "androidx-compose-latest"}
androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" }
androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" }
androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" }
Expand All @@ -103,12 +106,12 @@ androidx-glance = { module = "androidx.glance:glance", version.ref = "androidx-g
androidx-glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "androidx-glance" }
androidx-glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "androidx-glance" }
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-runtime ={ module= "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle-compose"}
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle-runtime-compose" }
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle-compose" }
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" }
androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidx-navigation" }
Expand Down
29 changes: 16 additions & 13 deletions Jetcaster/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ androidx-appcompat = "1.7.0"
androidx-benchmark = "1.2.4"
androidx-benchmark-junit4 = "1.2.4"
androidx-compose-bom = "2024.06.00"
androidx-compose-material3 = "1.3.0-beta01"
androidx-compose-material3-adaptive = "1.0.0-beta01"
androidx-constraintlayout = "1.0.1"
androidx-compose-latest = "1.7.0-beta07"
androidx-compose-material3 = "1.3.0-beta05"
androidx-compose-material3-adaptive = "1.0.0-beta04"
androidx-constraintlayout = "1.1.0-alpha13"
androidx-core-splashscreen = "1.0.1"
androidx-corektx = "1.13.1"
androidx-glance = "1.1.0"
androidx-lifecycle = "2.8.2"
androidx-lifecycle-compose = "2.6.1"
androidx-lifecycle-runtime-compose = "2.6.1"
androidx-navigation = "2.7.7"
androidx-palette = "1.0.0"
androidx-test = "1.5.0"
Expand Down Expand Up @@ -71,10 +74,10 @@ androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version.ref
androidx-appcompat = { module = "androidx.appcompat:appcompat", version.ref = "androidx-appcompat" }
androidx-benchmark-macrobenchmark = { module = "androidx.benchmark:benchmark-macro", version.ref = "androidx-benchmark" }
androidx-benchmark-macrobenchmark-junit4 = { module = "androidx.benchmark:benchmark-macro-junit4", version.ref = "androidx-benchmark-junit4" }
androidx-compose-animation = { module = "androidx.compose.animation:animation" }
androidx-compose-animation = { module = "androidx.compose.animation:animation", version.ref = "androidx-compose-latest" }
androidx-compose-bom = { module = "androidx.compose:compose-bom", version.ref = "androidx-compose-bom" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation" }
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" }
androidx-compose-foundation = { module = "androidx.compose.foundation:foundation", version.ref = "androidx-compose-latest"}
androidx-compose-foundation-layout = { module = "androidx.compose.foundation:foundation-layout" ,version.ref = "androidx-compose-latest"}
androidx-compose-material = { module = "androidx.compose.material:material" }
androidx-compose-material-iconsExtended = { module = "androidx.compose.material:material-icons-extended" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3" }
Expand All @@ -85,7 +88,7 @@ androidx-compose-material3-adaptive-navigationSuite = { module = "androidx.compo
androidx-compose-materialWindow = { module = "androidx.compose.material3:material3-window-size-class" }
androidx-compose-runtime = { module = "androidx.compose.runtime:runtime" }
androidx-compose-runtime-livedata = { module = "androidx.compose.runtime:runtime-livedata" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" }
androidx-compose-ui = { module = "androidx.compose.ui:ui" , version.ref = "androidx-compose-latest"}
androidx-compose-ui-googlefonts = { module = "androidx.compose.ui:ui-text-google-fonts" }
androidx-compose-ui-graphics = { module = "androidx.compose.ui:ui-graphics" }
androidx-compose-ui-test = { module = "androidx.compose.ui:ui-test" }
Expand All @@ -103,12 +106,12 @@ androidx-glance = { module = "androidx.glance:glance", version.ref = "androidx-g
androidx-glance-appwidget = { module = "androidx.glance:glance-appwidget", version.ref = "androidx-glance" }
androidx-glance-material3 = { module = "androidx.glance:glance-material3", version.ref = "androidx-glance" }
androidx-hilt-navigation-compose = { module = "androidx.hilt:hilt-navigation-compose", version.ref = "androidxHiltNavigationCompose" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle" }
androidx-lifecycle-livedata-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-runtime ={ module= "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle-compose"}
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidx-lifecycle-runtime-compose" }
androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle-compose" }
androidx-lifecycle-viewmodel-savedstate = { module = "androidx.lifecycle:lifecycle-viewmodel-savedstate", version.ref = "androidx-lifecycle-compose" }
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" }
androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidx-navigation" }
Expand Down
Loading

0 comments on commit d5c7da6

Please sign in to comment.