├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── res
│ │ │ ├── values
│ │ │ │ ├── strings.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── colors.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.webp
│ │ │ │ └── ic_launcher_round.webp
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── xml
│ │ │ │ ├── backup_rules.xml
│ │ │ │ └── data_extraction_rules.xml
│ │ │ ├── drawable-v24
│ │ │ │ └── ic_launcher_foreground.xml
│ │ │ └── drawable
│ │ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ │ └── dev
│ │ │ │ └── baseio
│ │ │ │ └── duolingodesign
│ │ │ │ ├── ui
│ │ │ │ └── theme
│ │ │ │ │ └── Theme.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── dev
│ │ │ └── baseio
│ │ │ └── cupertinoui
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── dev
│ │ └── baseio
│ │ └── cupertinoui
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── .idea
├── .name
├── .gitignore
├── compiler.xml
├── kotlinc.xml
├── vcs.xml
├── deploymentTargetDropDown.xml
├── misc.xml
├── gradle.xml
└── inspectionProfiles
│ └── Project_Default.xml
├── compose-duolingo
├── .gitignore
├── consumer-rules.pro
├── src
│ ├── main
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ │ └── dev
│ │ │ └── baseio
│ │ │ └── composeduolingo
│ │ │ ├── DuolingoTheme.kt
│ │ │ ├── DuolingoColors.kt
│ │ │ ├── primitives
│ │ │ ├── DuolingoText.kt
│ │ │ └── DuolingoButton.kt
│ │ │ ├── DuolingoBackground.kt
│ │ │ └── DuolingoBird.kt
│ ├── test
│ │ └── java
│ │ │ └── dev
│ │ │ └── baseio
│ │ │ └── composecupertino
│ │ │ └── ExampleUnitTest.kt
│ └── androidTest
│ │ └── java
│ │ └── dev
│ │ └── baseio
│ │ └── composecupertino
│ │ └── ExampleInstrumentedTest.kt
├── proguard-rules.pro
└── build.gradle
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── settings.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | DuolingoComposeUI
--------------------------------------------------------------------------------
/compose-duolingo/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/compose-duolingo/consumer-rules.pro:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | DuolingoComposeUI
3 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/oianmol/duolingo-design-system-jetpackcompose/master/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/compose-duolingo/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Aug 06 13:37:48 IST 2022
2 | distributionBase=GRADLE_USER_HOME
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
4 | distributionPath=wrapper/dists
5 | zipStorePath=wrapper/dists
6 | zipStoreBase=GRADLE_USER_HOME
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 | local.properties
16 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/compose-duolingo/src/test/java/dev/baseio/composecupertino/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo
2 |
3 |
4 | /**
5 | * Example local unit test, which will execute on the development machine (host).
6 | *
7 | * See [testing documentation](http://d.android.com/tools/testing).
8 | */
9 | class ExampleUnitTest {
10 | fun addition_isCorrect() {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 | rootProject.name = "DuolingoComposeUI"
16 | include ':app'
17 | include ':compose-duolingo'
18 |
--------------------------------------------------------------------------------
/compose-duolingo/src/androidTest/java/dev/baseio/composecupertino/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo
2 |
3 |
4 | /**
5 | * Instrumented test, which will execute on an Android device.
6 | *
7 | * See [testing documentation](http://d.android.com/tools/testing).
8 | */
9 | class ExampleInstrumentedTest {
10 | fun useAppContext() {
11 | // Context of the app under test.
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/test/java/dev/baseio/cupertinoui/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.duolingoui
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/dev/baseio/cupertinoui/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.duolingoui
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("dev.baseio.duolingoui", appContext.packageName)
23 | }
24 | }
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
19 |
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/compose-duolingo/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/duolingodesign/ui/theme/Theme.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.duolingodesign.ui.theme
2 |
3 | import androidx.compose.foundation.isSystemInDarkTheme
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.ui.graphics.Color
6 | import dev.baseio.composeduolingo.DuolingoColors
7 | import dev.baseio.composeduolingo.DuolingoTheme
8 |
9 | @Composable
10 | fun DuolingoComposeUITheme(
11 | darkTheme: Boolean = isSystemInDarkTheme(),
12 | content: @Composable () -> Unit
13 | ) {
14 | val colors = if (darkTheme) {
15 | DarkColorPalette
16 | } else {
17 | LightColorPalette
18 | }
19 |
20 | DuolingoTheme(
21 | duolingoColors = colors,
22 | content = content
23 | )
24 | }
25 |
26 | val DarkColorPalette = DuolingoColors(background = Color.Black, isLight = false, contentColor = Color.White)
27 | val LightColorPalette = DuolingoColors(background = Color.White, isLight = false, contentColor = Color.Black)
--------------------------------------------------------------------------------
/compose-duolingo/src/main/java/dev/baseio/composeduolingo/DuolingoTheme.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo
2 |
3 | import androidx.compose.runtime.Composable
4 | import androidx.compose.runtime.CompositionLocalProvider
5 | import androidx.compose.runtime.ReadOnlyComposable
6 | import androidx.compose.runtime.remember
7 |
8 | @Composable
9 | fun DuolingoTheme(
10 | duolingoColors: DuolingoColors = DuolingoTheme.duolingoColors,
11 | content: @Composable () -> Unit
12 | ) {
13 | val rememberedColors = remember {
14 | // Explicitly creating a new object here so we don't mutate the initial [colors]
15 | // provided, and overwrite the values set in it.
16 | duolingoColors.copy()
17 | }.apply { updateColorsFrom(duolingoColors) }
18 | CompositionLocalProvider(
19 | LocalColors provides rememberedColors,
20 | ) {
21 | content()
22 | }
23 | }
24 |
25 | object DuolingoTheme {
26 | val duolingoColors: DuolingoColors
27 | @Composable
28 | @ReadOnlyComposable
29 | get() = LocalColors.current
30 | }
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
16 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/compose-duolingo/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.library'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | compileSdk 32
8 |
9 | defaultConfig {
10 | minSdk 21
11 | targetSdk 32
12 |
13 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
14 | consumerProguardFiles "consumer-rules.pro"
15 | }
16 |
17 | buildTypes {
18 | release {
19 | minifyEnabled false
20 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
21 | }
22 | }
23 | buildFeatures {
24 | compose true
25 | }
26 | composeOptions {
27 | kotlinCompilerExtensionVersion compose_version
28 | }
29 | compileOptions {
30 | sourceCompatibility JavaVersion.VERSION_1_8
31 | targetCompatibility JavaVersion.VERSION_1_8
32 | }
33 | kotlinOptions {
34 | jvmTarget = '1.8'
35 | }
36 | }
37 |
38 | dependencies {
39 | implementation 'androidx.core:core-ktx:1.8.0'
40 | implementation "androidx.compose.ui:ui:$compose_version"
41 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
42 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
43 | debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
44 |
45 | implementation("androidx.compose.foundation:foundation:1.2.1")
46 | implementation("androidx.compose.foundation:foundation-layout:1.2.1")
47 | }
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Kotlin code style for this project: "official" or "obsolete":
19 | kotlin.code.style=official
20 | # Enables namespacing of each library's R class so that its R class includes only the
21 | # resources declared in the library itself and none from the library's dependencies,
22 | # thereby reducing the size of the R class for that library
23 | android.nonTransitiveRClass=true
--------------------------------------------------------------------------------
/compose-duolingo/src/main/java/dev/baseio/composeduolingo/DuolingoColors.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo
2 |
3 | import androidx.compose.runtime.*
4 | import androidx.compose.ui.graphics.Color
5 |
6 | class DuolingoColors(
7 | background: Color,
8 | contentColor: Color,
9 | surface: Color = background,
10 | isLight: Boolean
11 | ) {
12 | var background by mutableStateOf(background, structuralEqualityPolicy())
13 | internal set
14 | var surface by mutableStateOf(surface, structuralEqualityPolicy())
15 | internal set
16 | var contentColor by mutableStateOf(contentColor, structuralEqualityPolicy())
17 | internal set
18 | var isLight by mutableStateOf(isLight, structuralEqualityPolicy())
19 | internal set
20 |
21 | fun copy(
22 | background: Color = this.background,
23 | textColor: Color = this.contentColor,
24 | surface: Color = this.surface,
25 | isLight: Boolean = this.isLight
26 | ): DuolingoColors = DuolingoColors(
27 | background, textColor, surface, isLight
28 | )
29 |
30 | override fun toString(): String {
31 | return "Colors(" +
32 | "background=$background,textColor=$contentColor,surface=$surface,isLight=$isLight)"
33 | }
34 | }
35 |
36 | fun lightColors() = DuolingoColors(isLight = true, contentColor = Color.Black,surface = Color.White, background = Color.White)
37 | fun darkColors() = DuolingoColors(isLight = false, contentColor = Color.White, surface = Color.Black, background = Color.Black)
38 |
39 | internal fun DuolingoColors.updateColorsFrom(other: DuolingoColors) {
40 | background = other.background
41 | isLight = other.isLight
42 | }
43 |
44 | internal val LocalColors = staticCompositionLocalOf { lightColors() }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | id 'com.android.application'
3 | id 'org.jetbrains.kotlin.android'
4 | }
5 |
6 | android {
7 | compileSdk 32
8 |
9 | defaultConfig {
10 | applicationId "dev.baseio.duolingoui"
11 | minSdk 21
12 | targetSdk 32
13 | versionCode 1
14 | versionName "1.0"
15 |
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | vectorDrawables {
18 | useSupportLibrary true
19 | }
20 | }
21 |
22 | buildTypes {
23 | release {
24 | minifyEnabled false
25 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
26 | }
27 | }
28 | compileOptions {
29 | sourceCompatibility JavaVersion.VERSION_1_8
30 | targetCompatibility JavaVersion.VERSION_1_8
31 | }
32 | kotlinOptions {
33 | jvmTarget = '1.8'
34 | }
35 | buildFeatures {
36 | compose true
37 | }
38 | composeOptions {
39 | kotlinCompilerExtensionVersion compose_version
40 | }
41 | packagingOptions {
42 | resources {
43 | excludes += '/META-INF/{AL2.0,LGPL2.1}'
44 | }
45 | }
46 | }
47 |
48 | dependencies {
49 | implementation (project(':compose-duolingo',))
50 | implementation 'androidx.core:core-ktx:1.8.0'
51 | implementation "androidx.compose.ui:ui:$compose_version"
52 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"
53 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"
54 | debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
55 | implementation("androidx.compose.foundation:foundation:1.2.1")
56 | implementation("androidx.compose.foundation:foundation-layout:1.2.1")
57 |
58 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.1'
59 | implementation 'androidx.activity:activity-compose:1.5.1'
60 | testImplementation 'junit:junit:4.13.2'
61 | androidTestImplementation 'androidx.test.ext:junit:1.1.3'
62 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
63 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
64 |
65 | }
--------------------------------------------------------------------------------
/compose-duolingo/src/main/java/dev/baseio/composeduolingo/primitives/DuolingoText.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo.primitives
2 |
3 | import androidx.compose.foundation.text.BasicText
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.ui.Modifier
6 | import androidx.compose.ui.graphics.Color
7 | import androidx.compose.ui.text.TextLayoutResult
8 | import androidx.compose.ui.text.TextStyle
9 | import androidx.compose.ui.text.font.FontFamily
10 | import androidx.compose.ui.text.font.FontStyle
11 | import androidx.compose.ui.text.font.FontWeight
12 | import androidx.compose.ui.text.style.TextAlign
13 | import androidx.compose.ui.text.style.TextDecoration
14 | import androidx.compose.ui.text.style.TextOverflow
15 | import androidx.compose.ui.unit.TextUnit
16 | import dev.baseio.composeduolingo.DuolingoTheme
17 |
18 | @Composable
19 | fun DuolingoText(
20 | text: String,
21 | modifier: Modifier = Modifier,
22 | color: Color = DuolingoTheme.duolingoColors.contentColor,
23 | fontSize: TextUnit = TextUnit.Unspecified,
24 | fontStyle: FontStyle? = null,
25 | fontWeight: FontWeight? = null,
26 | fontFamily: FontFamily? = null,
27 | letterSpacing: TextUnit = TextUnit.Unspecified,
28 | textDecoration: TextDecoration? = null,
29 | textAlign: TextAlign? = null,
30 | lineHeight: TextUnit = TextUnit.Unspecified,
31 | overflow: TextOverflow = TextOverflow.Clip,
32 | softWrap: Boolean = true,
33 | maxLines: Int = Int.MAX_VALUE,
34 | onTextLayout: (TextLayoutResult) -> Unit = {},
35 | style: TextStyle
36 | ) {
37 | val mergedStyle = style.merge(
38 | TextStyle(
39 | color = color,
40 | fontSize = fontSize,
41 | fontWeight = fontWeight,
42 | textAlign = textAlign,
43 | lineHeight = lineHeight,
44 | fontFamily = fontFamily,
45 | textDecoration = textDecoration,
46 | fontStyle = fontStyle,
47 | letterSpacing = letterSpacing
48 | )
49 | )
50 | BasicText(
51 | text,
52 | modifier,
53 | mergedStyle,
54 | onTextLayout,
55 | overflow,
56 | softWrap,
57 | maxLines,
58 | )
59 | }
60 |
--------------------------------------------------------------------------------
/app/src/main/java/dev/baseio/duolingodesign/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.duolingodesign
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.compose.setContent
6 | import androidx.compose.foundation.BorderStroke
7 | import androidx.compose.foundation.layout.Column
8 | import androidx.compose.foundation.layout.fillMaxSize
9 | import androidx.compose.foundation.shape.RoundedCornerShape
10 | import androidx.compose.runtime.Composable
11 | import androidx.compose.ui.Modifier
12 | import androidx.compose.ui.text.TextStyle
13 | import androidx.compose.ui.tooling.preview.Preview
14 | import androidx.compose.ui.unit.dp
15 | import dev.baseio.composeduolingo.DuolingoSurface
16 | import dev.baseio.composeduolingo.DuolingoTheme
17 | import dev.baseio.composeduolingo.primitives.DuolingoButton
18 | import dev.baseio.composeduolingo.primitives.DuolingoText
19 | import dev.baseio.duolingodesign.ui.theme.DuolingoComposeUITheme
20 |
21 | class MainActivity : ComponentActivity() {
22 | override fun onCreate(savedInstanceState: Bundle?) {
23 | super.onCreate(savedInstanceState)
24 | setContent {
25 | DuolingoComposeUITheme {
26 | // A surface container using the 'background' color from the theme
27 | Greeting()
28 | }
29 | }
30 | }
31 | }
32 |
33 | @Composable
34 | fun Greeting() {
35 | DuolingoSurface(Modifier.fillMaxSize()) {
36 | Column {
37 | repeat(4) { index ->
38 | DuolingoButton(
39 | onClick = {
40 | },
41 | elevation = 4.dp,
42 | border = BorderStroke(1.dp, color = DuolingoTheme.duolingoColors.contentColor),
43 | shape = RoundedCornerShape(8.dp),
44 | ) {
45 | DuolingoText("Test Text $index", style = TextStyle())
46 | }
47 | }
48 | }
49 | }
50 | }
51 |
52 | @Preview(showBackground = true)
53 | @Composable
54 | fun DefaultPreview() {
55 | DuolingoComposeUITheme {
56 | Greeting()
57 | }
58 | }
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/compose-duolingo/src/main/java/dev/baseio/composeduolingo/primitives/DuolingoButton.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo.primitives
2 |
3 | import androidx.compose.foundation.BorderStroke
4 | import androidx.compose.foundation.interaction.MutableInteractionSource
5 | import androidx.compose.foundation.layout.*
6 | import androidx.compose.runtime.Composable
7 | import androidx.compose.runtime.remember
8 | import androidx.compose.ui.Alignment
9 | import androidx.compose.ui.Modifier
10 | import androidx.compose.ui.graphics.RectangleShape
11 | import androidx.compose.ui.graphics.Shape
12 | import androidx.compose.ui.unit.Dp
13 | import androidx.compose.ui.unit.dp
14 | import dev.baseio.composeduolingo.DuolingoSurface
15 |
16 | @Composable
17 | fun DuolingoButton(
18 | onClick: () -> Unit,
19 | modifier: Modifier = Modifier,
20 | enabled: Boolean = true,
21 | elevation: Dp,
22 | border: BorderStroke? = null,
23 | shape: Shape = RectangleShape,
24 | interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
25 | contentPadding: PaddingValues = ButtonDefaults.ContentPadding,
26 | content: @Composable RowScope.() -> Unit
27 | ) {
28 | DuolingoSurface(
29 | onClick = onClick,
30 | modifier = modifier,
31 | enabled = enabled,
32 | border = border,
33 | shape = shape,
34 | elevation = elevation,
35 | interactionSource = interactionSource,
36 | ){
37 | Row(
38 | Modifier
39 | .defaultMinSize(
40 | minWidth = ButtonDefaults.MinWidth,
41 | minHeight = ButtonDefaults.MinHeight
42 | )
43 | .padding(contentPadding),
44 | horizontalArrangement = Arrangement.Center,
45 | verticalAlignment = Alignment.CenterVertically,
46 | content = content
47 | )
48 | }
49 |
50 | }
51 |
52 | object ButtonDefaults {
53 | private val ButtonHorizontalPadding = 16.dp
54 | private val ButtonVerticalPadding = 8.dp
55 |
56 | /**
57 | * The default content padding used by [Button]
58 | */
59 | val ContentPadding = PaddingValues(
60 | start = ButtonHorizontalPadding,
61 | top = ButtonVerticalPadding,
62 | end = ButtonHorizontalPadding,
63 | bottom = ButtonVerticalPadding
64 | )
65 |
66 | /**
67 | * The default min width applied for the [Button].
68 | * Note that you can override it by applying Modifier.widthIn directly on [Button].
69 | */
70 | val MinWidth = 64.dp
71 |
72 | /**
73 | * The default min height applied for the [Button].
74 | * Note that you can override it by applying Modifier.heightIn directly on [Button].
75 | */
76 | val MinHeight = 36.dp
77 |
78 | /**
79 | * The default size of the icon when used inside a [Button].
80 | *
81 | * @sample androidx.compose.material.samples.ButtonWithIconSample
82 | */
83 | val IconSize = 18.dp
84 |
85 | /**
86 | * The default size of the spacing between an icon and a text when they used inside a [Button].
87 | *
88 | * @sample androidx.compose.material.samples.ButtonWithIconSample
89 | */
90 | val IconSpacing = 8.dp
91 |
92 | /**
93 | * The default color opacity used for an [OutlinedButton]'s border color
94 | */
95 | const val OutlinedBorderOpacity = 0.12f
96 |
97 | /**
98 | * The default [OutlinedButton]'s border size
99 | */
100 | val OutlinedBorderSize = 1.dp
101 |
102 | private val TextButtonHorizontalPadding = 8.dp
103 |
104 | /**
105 | * The default content padding used by [TextButton]
106 | */
107 | val TextButtonContentPadding = PaddingValues(
108 | start = TextButtonHorizontalPadding,
109 | top = ContentPadding.calculateTopPadding(),
110 | end = TextButtonHorizontalPadding,
111 | bottom = ContentPadding.calculateBottomPadding()
112 | )
113 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/compose-duolingo/src/main/java/dev/baseio/composeduolingo/DuolingoBackground.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo
2 |
3 | import androidx.compose.animation.core.animateFloatAsState
4 | import androidx.compose.foundation.BorderStroke
5 | import androidx.compose.foundation.background
6 | import androidx.compose.foundation.border
7 | import androidx.compose.foundation.clickable
8 | import androidx.compose.foundation.interaction.MutableInteractionSource
9 | import androidx.compose.foundation.interaction.collectIsPressedAsState
10 | import androidx.compose.foundation.layout.Box
11 | import androidx.compose.foundation.layout.Column
12 | import androidx.compose.foundation.layout.size
13 | import androidx.compose.foundation.selection.selectable
14 | import androidx.compose.foundation.selection.toggleable
15 | import androidx.compose.runtime.*
16 | import androidx.compose.ui.Modifier
17 | import androidx.compose.ui.draw.clip
18 | import androidx.compose.ui.draw.shadow
19 | import androidx.compose.ui.graphics.Color
20 | import androidx.compose.ui.graphics.RectangleShape
21 | import androidx.compose.ui.graphics.Shape
22 | import androidx.compose.ui.graphics.graphicsLayer
23 | import androidx.compose.ui.input.pointer.pointerInput
24 | import androidx.compose.ui.layout.onSizeChanged
25 | import androidx.compose.ui.platform.LocalDensity
26 | import androidx.compose.ui.semantics.Role
27 | import androidx.compose.ui.semantics.semantics
28 | import androidx.compose.ui.unit.Dp
29 | import androidx.compose.ui.unit.dp
30 | import androidx.compose.ui.zIndex
31 |
32 | @Composable
33 | fun DuolingoSurface(
34 | modifier: Modifier = Modifier,
35 | shape: Shape = RectangleShape,
36 | color: Color = DuolingoTheme.duolingoColors.surface,
37 | border: BorderStroke? = null,
38 | elevation: Dp = 0.dp,
39 | content: @Composable () -> Unit
40 | ) {
41 | Box(
42 | modifier = modifier
43 | .surface(
44 | shape = shape,
45 | backgroundColor = color,
46 | border = border,
47 | elevation = elevation
48 | )
49 | .semantics(mergeDescendants = false) {}
50 | .pointerInput(Unit) {},
51 | propagateMinConstraints = true
52 | ) {
53 | content()
54 | }
55 | }
56 |
57 | @Composable
58 | fun DuolingoSurface(
59 | onClick: () -> Unit,
60 | modifier: Modifier = Modifier,
61 | enabled: Boolean = true,
62 | shape: Shape = RectangleShape,
63 | color: Color = DuolingoTheme.duolingoColors.surface,
64 | border: BorderStroke? = null,
65 | elevation: Dp = 0.dp,
66 | interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
67 | content: @Composable () -> Unit
68 | ) {
69 | val density = LocalDensity.current
70 |
71 | var bottomBarWidth: Dp by remember { mutableStateOf(0.dp) }
72 |
73 | val bottomBarHeight = remember(elevation) { elevation * 2 }
74 |
75 | val isPressed by interactionSource.collectIsPressedAsState()
76 |
77 | val contentTranslationY by animateFloatAsState(
78 | targetValue = with(density) {
79 | if (!isPressed) elevation.times(1.5f).toPx() else bottomBarHeight.toPx()
80 | }
81 | )
82 |
83 | Column(modifier = Modifier.clip(shape)) {
84 | Box(
85 | modifier = modifier
86 | .graphicsLayer { translationY = contentTranslationY }
87 | .surface(
88 | shape = shape,
89 | backgroundColor = color,
90 | border = border,
91 | elevation = elevation
92 | )
93 | .clickable(
94 | interactionSource = interactionSource,
95 | indication = null,
96 | enabled = enabled,
97 | role = Role.Button,
98 | onClick = onClick
99 | )
100 | .onSizeChanged { size -> bottomBarWidth = with(density) { size.width.toDp() } }
101 | .zIndex(1f),
102 | propagateMinConstraints = true
103 | ) {
104 | content()
105 | }
106 | border?.let { nnBorder ->
107 | Box(
108 | modifier = Modifier
109 | .size(
110 | width = bottomBarWidth,
111 | height = bottomBarHeight,
112 | )
113 | .background(nnBorder.brush)
114 | )
115 | }
116 | }
117 | }
118 |
119 | @Composable
120 | fun DuolingoSurface(
121 | selected: Boolean,
122 | onClick: () -> Unit,
123 | modifier: Modifier = Modifier,
124 | enabled: Boolean = true,
125 | shape: Shape = RectangleShape,
126 | color: Color = DuolingoTheme.duolingoColors.surface,
127 | border: BorderStroke? = null,
128 | elevation: Dp = 0.dp,
129 | interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
130 | content: @Composable () -> Unit
131 | ) {
132 | Box(
133 | modifier = modifier
134 | .surface(
135 | shape = shape,
136 | backgroundColor = color,
137 | border = border,
138 | elevation = elevation
139 | )
140 | .selectable(
141 | selected = selected,
142 | interactionSource = interactionSource,
143 | indication = null,
144 | enabled = enabled,
145 | role = Role.Tab,
146 | onClick = onClick
147 | ),
148 | propagateMinConstraints = true
149 | ) {
150 | content()
151 | }
152 | }
153 |
154 |
155 | @Composable
156 | fun DuolingoSurface(
157 | checked: Boolean,
158 | onCheckedChange: (Boolean) -> Unit,
159 | modifier: Modifier = Modifier,
160 | enabled: Boolean = true,
161 | shape: Shape = RectangleShape,
162 | color: Color = DuolingoTheme.duolingoColors.surface,
163 | border: BorderStroke? = null,
164 | elevation: Dp = 0.dp,
165 | interactionSource: MutableInteractionSource = remember { MutableInteractionSource() },
166 | content: @Composable () -> Unit
167 | ) {
168 | Box(
169 | modifier = modifier
170 | .surface(
171 | shape = shape,
172 | backgroundColor = color,
173 | border = border,
174 | elevation = elevation
175 | )
176 | .toggleable(
177 | value = checked,
178 | interactionSource = interactionSource,
179 | indication = null,
180 | enabled = enabled,
181 | role = Role.Switch,
182 | onValueChange = onCheckedChange
183 | ),
184 | propagateMinConstraints = true
185 | ) {
186 | content()
187 | }
188 | }
189 |
190 | private fun Modifier.surface(
191 | shape: Shape,
192 | backgroundColor: Color,
193 | border: BorderStroke?,
194 | elevation: Dp
195 | ) = this
196 | .shadow(elevation, shape, clip = false)
197 | .then(if (border != null) Modifier.border(border, shape) else Modifier)
198 | .background(color = backgroundColor, shape = shape)
199 | .clip(shape)
200 |
--------------------------------------------------------------------------------
/compose-duolingo/src/main/java/dev/baseio/composeduolingo/DuolingoBird.kt:
--------------------------------------------------------------------------------
1 | package dev.baseio.composeduolingo
2 |
3 | import androidx.compose.animation.core.Animatable
4 | import androidx.compose.animation.core.FastOutSlowInEasing
5 | import androidx.compose.animation.core.InfiniteRepeatableSpec
6 | import androidx.compose.animation.core.LinearOutSlowInEasing
7 | import androidx.compose.animation.core.RepeatMode.Reverse
8 | import androidx.compose.animation.core.Spring
9 | import androidx.compose.animation.core.animateFloat
10 | import androidx.compose.animation.core.rememberInfiniteTransition
11 | import androidx.compose.animation.core.spring
12 | import androidx.compose.animation.core.tween
13 | import androidx.compose.foundation.Canvas
14 | import androidx.compose.foundation.background
15 | import androidx.compose.foundation.clickable
16 | import androidx.compose.foundation.layout.Box
17 | import androidx.compose.foundation.layout.BoxScope
18 | import androidx.compose.foundation.layout.fillMaxSize
19 | import androidx.compose.foundation.layout.height
20 | import androidx.compose.foundation.layout.offset
21 | import androidx.compose.foundation.layout.width
22 | import androidx.compose.runtime.Composable
23 | import androidx.compose.runtime.LaunchedEffect
24 | import androidx.compose.runtime.Stable
25 | import androidx.compose.runtime.getValue
26 | import androidx.compose.runtime.mutableStateOf
27 | import androidx.compose.runtime.remember
28 | import androidx.compose.runtime.setValue
29 | import androidx.compose.ui.Alignment
30 | import androidx.compose.ui.Modifier
31 | import androidx.compose.ui.draw.rotate
32 | import androidx.compose.ui.draw.scale
33 | import androidx.compose.ui.geometry.CornerRadius
34 | import androidx.compose.ui.graphics.Color
35 | import androidx.compose.ui.graphics.Path
36 | import androidx.compose.ui.graphics.graphicsLayer
37 | import androidx.compose.ui.unit.dp
38 |
39 | val toeColor = Color(230, 149, 53)
40 | val birdGreen = Color(120, 201, 60)
41 | val birdLightGreen = Color(152, 216, 71)
42 | val birdBeak = Color(246, 196, 52)
43 | val birdBeakBelow = Color(230, 149, 53)
44 |
45 | @Composable
46 | fun DuolingoBird(modifier: Modifier = Modifier) {
47 |
48 | var scale by remember {
49 | mutableStateOf(1f)
50 | }
51 |
52 | val scalingAnim = remember {
53 | Animatable(scale)
54 | }
55 |
56 | val repeteableAnim = rememberInfiniteTransition()
57 |
58 | val rotateLeft by repeteableAnim.animateFloat(
59 | initialValue = 8f, targetValue = -4f,
60 | animationSpec = InfiniteRepeatableSpec(
61 | animation = tween(durationMillis = 250, easing = FastOutSlowInEasing),
62 | repeatMode = Reverse
63 | )
64 | )
65 |
66 | val beakSpace by repeteableAnim.animateFloat(
67 | initialValue = 16f, targetValue = 0f,
68 | animationSpec = InfiniteRepeatableSpec(
69 | animation = tween(durationMillis = 400, easing = LinearOutSlowInEasing),
70 | repeatMode = Reverse
71 | )
72 | )
73 |
74 | val eyeBallsMoveLeft by repeteableAnim.animateFloat(
75 | initialValue = -16f, targetValue = 16f, animationSpec = InfiniteRepeatableSpec(
76 | animation = tween(durationMillis = 500, easing = FastOutSlowInEasing),
77 | repeatMode = Reverse
78 | )
79 | )
80 | val eyeBallsMoveRight by repeteableAnim.animateFloat(
81 | initialValue = 16f, targetValue = -16f, animationSpec = InfiniteRepeatableSpec(
82 | animation = tween(durationMillis = 500, easing = FastOutSlowInEasing),
83 | repeatMode = Reverse
84 | )
85 | )
86 |
87 | val toeRotateLeft by repeteableAnim.animateFloat(
88 | initialValue = 0f,
89 | targetValue = 20f, animationSpec = InfiniteRepeatableSpec(
90 | animation = tween(durationMillis = 500, easing = FastOutSlowInEasing),
91 | repeatMode = Reverse
92 | )
93 | )
94 | val toeRotateRight by repeteableAnim.animateFloat(
95 | initialValue = 0f,
96 | targetValue = 30f, animationSpec = InfiniteRepeatableSpec(
97 | animation = tween(durationMillis = 500, easing = FastOutSlowInEasing),
98 | repeatMode = Reverse
99 | )
100 | )
101 | val bodyRotateRight by repeteableAnim.animateFloat(
102 | initialValue = 0f,
103 | targetValue = 40f, animationSpec = InfiniteRepeatableSpec(
104 | animation = tween(durationMillis = 1000, easing = FastOutSlowInEasing),
105 | repeatMode = Reverse
106 | )
107 | )
108 |
109 | val bodyTranslationY by repeteableAnim.animateFloat(
110 | initialValue = 0f,
111 | targetValue = -40f, animationSpec = InfiniteRepeatableSpec(
112 | animation = tween(durationMillis = 500, easing = FastOutSlowInEasing),
113 | repeatMode = Reverse
114 | )
115 | )
116 |
117 | LaunchedEffect(key1 = scale, block = {
118 | scalingAnim.animateTo(
119 | scale,
120 | spring(dampingRatio = Spring.DampingRatioHighBouncy, stiffness = Spring.StiffnessLow)
121 | )
122 | })
123 |
124 | Box(modifier = modifier
125 | .clickable {
126 | scale = if (scale == 1f) 56f else 1f
127 | }
128 | .graphicsLayer(translationY = scalingAnim.value)) {
129 | BirdToes(toeRotateLeft,toeRotateRight)
130 | Box(
131 | modifier = Modifier.graphicsLayer(
132 | rotationZ = bodyRotateRight,
133 | translationY = bodyTranslationY
134 | )
135 | ) {
136 | BirdBody(rotateLeft, 0f, eyeBallsMoveLeft, eyeBallsMoveRight, beakSpace)
137 | }
138 | }
139 | }
140 |
141 | @Composable
142 | private fun BoxScope.BirdToes(toeRotateLeft: Float,toeRotateRight: Float) {
143 | BirdToes(
144 | Modifier
145 | .rotate(toeRotateRight)
146 | .offset(x = 15.dp, y = (40).dp))
147 | BirdToes(
148 | Modifier
149 | .rotate(toeRotateLeft)
150 | .offset(x = (-30).dp, y = (40).dp)
151 | )
152 | }
153 |
154 | @Composable
155 | private fun BoxScope.BirdBody(
156 | rotateLeft: Float,
157 | rotateRight: Float,
158 | eyeBallsMoveLeft: Float,
159 | eyeBallsMoveRight: Float,
160 | beakSpace: Float
161 | ) {
162 | BirdHands(rotateLeft, rotateRight)
163 | BirdMainShape(Modifier.offset(y = (-120).dp, x = (-80).dp))
164 | BirdFaceEyeBG(Modifier.offset(y = -120.dp, x = -80.dp))
165 | BirdEye(Modifier.offset(y = (-75).dp, x = -38.dp), eyeBallsMoveLeft)
166 | BirdEye(Modifier.offset(y = (-75).dp, x = 25.dp), eyeBallsMoveRight)
167 | BirdBeak(beakSpace)
168 | BirdCenterPatch()
169 | }
170 |
171 | @Composable
172 | private fun BoxScope.BirdCenterPatch() {
173 | BirdCenterPatch(Modifier.offset(y = (-115).dp, x = (-70).dp))
174 | BirdCenterPatch(Modifier.offset(y = (-130).dp, x = (-50).dp))
175 | BirdCenterPatch(Modifier.offset(y = (-130).dp, x = (-90).dp))
176 | }
177 |
178 | @Composable
179 | private fun BoxScope.BirdBeak(beakSpace: Float) {
180 | BirdBeakTop(Modifier.offset(y = -120.dp, x = -80.dp))
181 | BirdBreakBelow(
182 | Modifier
183 | .offset(y = -118.dp, x = -80.dp)
184 | .graphicsLayer(translationY = beakSpace)
185 | )
186 | }
187 |
188 | @Composable
189 | private fun BoxScope.BirdHands(rotateLeft: Float, rotateRight: Float) {
190 | BirdHands(
191 | Modifier
192 | .offset(y = (-130).dp, x = (110).dp)
193 | .mirror()
194 | .graphicsLayer(rotationZ = rotateLeft),
195 | )
196 | BirdHands(
197 | Modifier
198 | .offset(y = (-130).dp, x = (-85).dp)
199 | .graphicsLayer(rotationZ = rotateRight)
200 | )
201 | }
202 |
203 | @Composable
204 | fun BirdBeakTop(modifier: Modifier = Modifier) {
205 | Canvas(modifier = modifier, onDraw = {
206 | Path().apply {
207 | val xmul = 1f
208 | val xoff = 1f
209 | val ymul = 1f
210 | val yoff = 1f
211 | lineTo(255 * xmul + xoff, 249 * ymul + yoff);
212 | lineTo(222 * xmul + xoff, 241 * ymul + yoff);
213 | cubicTo(
214 | 225 * xmul + xoff, 209 * ymul + yoff, 276 * xmul + xoff, 212 * ymul + yoff,
215 | 256 * xmul + xoff, 212 * ymul + yoff
216 | )
217 | cubicTo(
218 | 285 * xmul + xoff, 216 * ymul + yoff, 293 * xmul + xoff, 241 * ymul + yoff,
219 | 289 * xmul + xoff, 242 * ymul + yoff
220 | )
221 | lineTo(255 * xmul + xoff, 249 * ymul + yoff);
222 |
223 | drawPath(this, birdBeak)
224 |
225 | }
226 | })
227 | }
228 |
229 | @Composable
230 | fun BirdBreakBelow(modifier: Modifier = Modifier) {
231 | Canvas(modifier = modifier, onDraw = {
232 | Path().apply {
233 | val xmul = 1f
234 | val xoff = 1f
235 | val ymul = 1f
236 | val yoff = 1f
237 | lineTo(279 * xmul + xoff, 244 * ymul + yoff);
238 | lineTo(255 * xmul + xoff, 248 * ymul + yoff);
239 | lineTo(232 * xmul + xoff, 242 * ymul + yoff);
240 | cubicTo(
241 | 233 * xmul + xoff, 244 * ymul + yoff, 226 * xmul + xoff, 265 * ymul + yoff,
242 | 255 * xmul + xoff, 271 * ymul + yoff
243 | )
244 | cubicTo(
245 | 276 * xmul + xoff, 273 * ymul + yoff, 280 * xmul + xoff, 246 * ymul + yoff,
246 | 282 * xmul + xoff, 246 * ymul + yoff
247 | )
248 |
249 | drawPath(this, birdBeakBelow)
250 |
251 | }
252 | })
253 | }
254 |
255 | @Composable
256 | fun BoxScope.BirdEye(
257 | modifier: Modifier = Modifier,
258 | eyeBallsMove: Float
259 | ) {
260 |
261 | Canvas(modifier = modifier
262 | .width(40.dp)
263 | .height(50.dp)
264 | .scale(0.8f), onDraw = {
265 | drawOval(Color.White)
266 | })
267 |
268 | Canvas(modifier = modifier
269 | .align(Alignment.Center)
270 | .width(40.dp)
271 | .height(50.dp)
272 | .scale(0.4f)
273 | .graphicsLayer(translationX = eyeBallsMove), onDraw = {
274 | drawOval(Color.Black)
275 | })
276 | }
277 |
278 | @Composable
279 | fun BirdFaceEyeBG(modifier: Modifier = Modifier) {
280 | Canvas(modifier = modifier, onDraw = {
281 | Path().apply {
282 | val xmul = 1f
283 | val xoff = 1f
284 | val ymul = 1f
285 | val yoff = 1f
286 | moveTo(232 * xmul + xoff, 245 * ymul + yoff);
287 | cubicTo(
288 | 175 * xmul + xoff, 328 * ymul + yoff, 109 * xmul + xoff, 257 * ymul + yoff,
289 | 106 * xmul + xoff, 241 * ymul + yoff
290 | )
291 | cubicTo(
292 | 102.3142292989963f * xmul + xoff,
293 | 221.34255626131358f * ymul + yoff,
294 | 85 * xmul + xoff,
295 | 137 * ymul + yoff,
296 | 129 * xmul + xoff,
297 | 123 * ymul + yoff
298 | )
299 | cubicTo(
300 | 133 * xmul + xoff, 143 * ymul + yoff, 121 * xmul + xoff, 90 * ymul + yoff,
301 | 139 * xmul + xoff, 92 * ymul + yoff
302 | )
303 | cubicTo(
304 | 119 * xmul + xoff, 76 * ymul + yoff, 158 * xmul + xoff, 101 * ymul + yoff,
305 | 160 * xmul + xoff, 110 * ymul + yoff
306 | )
307 | cubicTo(
308 | 158 * xmul + xoff,
309 | 64 * ymul + yoff,
310 | 179 * xmul + xoff,
311 | 73 * ymul + yoff,
312 | 169 * xmul + xoff,
313 | 77 * ymul + yoff
314 | )
315 | cubicTo(
316 | 225 * xmul + xoff, 115 * ymul + yoff, 212 * xmul + xoff, 143 * ymul + yoff,
317 | 255 * xmul + xoff, 145 * ymul + yoff
318 | )
319 | cubicTo(
320 | 317 * xmul + xoff, 129 * ymul + yoff, 311 * xmul + xoff, 95 * ymul + yoff,
321 | 342 * xmul + xoff, 78 * ymul + yoff
322 | )
323 | cubicTo(
324 | 350 * xmul + xoff, 66 * ymul + yoff, 356 * xmul + xoff, 113 * ymul + yoff,
325 | 357 * xmul + xoff, 110 * ymul + yoff
326 | )
327 | cubicTo(
328 | 369 * xmul + xoff,
329 | 79 * ymul + yoff,
330 | 395 * xmul + xoff,
331 | 91 * ymul + yoff,
332 | 375 * xmul + xoff,
333 | 91 * ymul + yoff
334 | )
335 | cubicTo(
336 | 385 * xmul + xoff, 84 * ymul + yoff, 389 * xmul + xoff, 130 * ymul + yoff,
337 | 385 * xmul + xoff, 122 * ymul + yoff
338 | )
339 | cubicTo(
340 | 394 * xmul + xoff, 119 * ymul + yoff, 421 * xmul + xoff, 158 * ymul + yoff,
341 | 412 * xmul + xoff, 218 * ymul + yoff
342 | )
343 | cubicTo(
344 | 399 * xmul + xoff, 285 * ymul + yoff, 358 * xmul + xoff, 281 * ymul + yoff,
345 | 338 * xmul + xoff, 281 * ymul + yoff
346 | )
347 | cubicTo(
348 | 318 * xmul + xoff, 281 * ymul + yoff, 288 * xmul + xoff, 269 * ymul + yoff,
349 | 282 * xmul + xoff, 243 * ymul + yoff
350 | )
351 | drawPath(this, birdLightGreen)
352 |
353 | }
354 | })
355 | }
356 |
357 | @Composable
358 | fun BirdCenterPatch(modifier: Modifier = Modifier) {
359 | Canvas(modifier = modifier, onDraw = {
360 | Path().apply {
361 | val xmul = 1f
362 | val xoff = 1f
363 | val ymul = 1f
364 | val yoff = 1f
365 | lineTo(192 * xmul + xoff, 340 * ymul + yoff);
366 | lineTo(245 * xmul + xoff, 340 * ymul + yoff);
367 | cubicTo(
368 | 250 * xmul + xoff, 340 * ymul + yoff, 238 * xmul + xoff, 362 * ymul + yoff,
369 | 218 * xmul + xoff, 362 * ymul + yoff
370 | )
371 | cubicTo(
372 | 198 * xmul + xoff, 362 * ymul + yoff, 195 * xmul + xoff, 340 * ymul + yoff,
373 | 192 * xmul + xoff, 340 * ymul + yoff
374 | )
375 | drawPath(this, birdLightGreen)
376 | }
377 | })
378 | }
379 |
380 | @Composable
381 | fun BirdMainShape(modifier: Modifier = Modifier) {
382 | Canvas(modifier = modifier, onDraw = {
383 | Path().apply {
384 | val xmul = 1f
385 | val xoff = 1f
386 | val ymul = 1f
387 | val yoff = 1f
388 | lineTo(83 * xmul + xoff, 132 * ymul + yoff);
389 | cubicTo(
390 | 84 * xmul + xoff,
391 | 121 * ymul + yoff,
392 | 59 * xmul + xoff,
393 | 383 * ymul + yoff,
394 | 141 * xmul + xoff,
395 | 411 * ymul + yoff
396 | )
397 | cubicTo(
398 | 191 * xmul + xoff, 480 * ymul + yoff, 342 * xmul + xoff, 476 * ymul + yoff,
399 | 395 * xmul + xoff, 391 * ymul + yoff
400 | )
401 | cubicTo(
402 | 405.5820258211916f * xmul + xoff,
403 | 374.0288265131832f * ymul + yoff,
404 | 439 * xmul + xoff,
405 | 282 * ymul + yoff,
406 | 429 * xmul + xoff,
407 | 133 * ymul + yoff
408 | )
409 | cubicTo(
410 | 437 * xmul + xoff,
411 | 29 * ymul + yoff,
412 | 353 * xmul + xoff,
413 | 44 * ymul + yoff,
414 | 335 * xmul + xoff,
415 | 57 * ymul + yoff
416 | )
417 | cubicTo(
418 | 318.7864154320024f * xmul + xoff,
419 | 68.70981107688718f * ymul + yoff,
420 | 278 * xmul + xoff,
421 | 82 * ymul + yoff,
422 | 258 * xmul + xoff,
423 | 82 * ymul + yoff
424 | )
425 | cubicTo(
426 | 234 * xmul + xoff,
427 | 93 * ymul + yoff,
428 | 163 * xmul + xoff,
429 | 33 * ymul + yoff,
430 | 124 * xmul + xoff,
431 | 48 * ymul + yoff
432 | )
433 | cubicTo(
434 | 49 * xmul + xoff,
435 | 88 * ymul + yoff,
436 | 102 * xmul + xoff,
437 | 145 * ymul + yoff,
438 | 83 * xmul + xoff,
439 | 132 * ymul + yoff
440 | )
441 | drawPath(this, birdGreen)
442 | }
443 | })
444 | }
445 |
446 | @Composable
447 | fun BirdHands(modifier: Modifier = Modifier) {
448 | Canvas(modifier = modifier, onDraw = {
449 | Path().apply {
450 | val xmul = 1f
451 | val xoff = 1f
452 | val ymul = 1f
453 | val yoff = 1f
454 |
455 | moveTo(426 * xmul + xoff, 247 * ymul + yoff);
456 | cubicTo(
457 | 418 * xmul + xoff, 251 * ymul + yoff, 510 * xmul + xoff, 378 * ymul + yoff,
458 | 500 * xmul + xoff, 390 * ymul + yoff
459 | )
460 | cubicTo(
461 | 457 * xmul + xoff, 447 * ymul + yoff, 302 * xmul + xoff, 360 * ymul + yoff,
462 | 298 * xmul + xoff, 360 * ymul + yoff
463 | )
464 |
465 | drawPath(this, color = birdGreen)
466 | }
467 | })
468 | }
469 |
470 | @Composable
471 | fun BoxScope.BirdToes(modifier: Modifier = Modifier) {
472 | Canvas(modifier = modifier
473 | .width(40.dp)
474 | .height(20.dp), onDraw = {
475 | drawRoundRect(color = toeColor, cornerRadius = CornerRadius(24f, 24f))
476 | })
477 | }
478 |
479 | @androidx.compose.ui.tooling.preview.Preview
480 | @Composable
481 | fun PreviewDuolingoBird() {
482 | DuolingoTheme {
483 | DuolingoSurface(
484 | Modifier
485 | .background(Color.Black)
486 | .fillMaxSize()) {
487 | Box(modifier = Modifier.background(Color.Black)) {
488 | DuolingoBird(Modifier.align(Alignment.Center))
489 | }
490 | }
491 | }
492 | }
493 |
494 | @Stable
495 | fun Modifier.mirror(): Modifier {
496 | return this.scale(scaleX = -1f, scaleY = 1f)
497 | }
--------------------------------------------------------------------------------