├── .gitignore
├── .idea
├── .gitignore
├── .name
├── compiler.xml
├── deploymentTargetDropDown.xml
├── gradle.xml
├── kotlinc.xml
├── misc.xml
└── vcs.xml
├── LICENSE
├── README.md
├── app
├── .gitignore
├── build.gradle.kts
├── jitpack.yml
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ ├── java
│ └── com
│ │ └── alexmercerind
│ │ └── example
│ │ ├── AnimatedTextScreen.kt
│ │ ├── Destinations.kt
│ │ ├── HomeScreen.kt
│ │ └── MainActivity.kt
│ └── res
│ ├── drawable-v24
│ └── ic_launcher_foreground.xml
│ ├── drawable
│ ├── baseline_code_24.xml
│ ├── baseline_pause_24.xml
│ ├── baseline_shutter_speed_24.xml
│ ├── baseline_stop_24.xml
│ ├── github.xml
│ └── ic_launcher_background.xml
│ ├── mipmap-anydpi-v26
│ ├── ic_launcher.xml
│ └── ic_launcher_round.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
│ ├── values
│ ├── colors.xml
│ ├── strings.xml
│ └── themes.xml
│ └── xml
│ ├── backup_rules.xml
│ └── data_extraction_rules.xml
├── build.gradle.kts
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── moving-letters
├── .gitignore
├── build.gradle.kts
├── consumer-rules.pro
├── proguard-rules.pro
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── alexmercerind
│ └── movingletters
│ ├── AnimatedTextState.kt
│ ├── FadeAnimatedText.kt
│ ├── JumpAnimatedText.kt
│ ├── RotateAnimatedText.kt
│ ├── ScaleInAnimatedText.kt
│ └── ScaleOutAnimatedText.kt
└── settings.gradle.kts
/.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 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/.name:
--------------------------------------------------------------------------------
1 | Moving Letters Example
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/deploymentTargetDropDown.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
20 |
21 |
--------------------------------------------------------------------------------
/.idea/kotlinc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2023 & onwards, Hitesh Kumar Saini
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # [moving-letters-android](https://github.com/alexmercerind/moving-letters-android)
2 |
3 | #### Text animation library for Android (Jetpack Compose).
4 |
5 | ## Guide
6 |
7 | Following text animations are available:
8 |
9 | #### ScaleInAnimatedText
10 |
11 |
12 |
13 | #### ScaleOutAnimatedText
14 |
15 |
16 |
17 | #### FadeAnimatedText
18 |
19 |
20 |
21 | #### JumpAnimatedText
22 |
23 |
24 |
25 | #### RotateAnimatedText
26 |
27 |
28 |
29 | #### Programmatic API
30 |
31 | You may use `AnimatedTextState` as follows to control the animation programmatically:
32 |
33 | ```kt
34 | val state = rememberAnimatedTextState()
35 |
36 | XYZAnimatedText(
37 | state = state,
38 | text = "I like Jetpack Compose"
39 | )
40 |
41 | state.stop()
42 | state.pause()
43 | state.start()
44 | state.resume()
45 | ```
46 |
47 | #### Example Application
48 |
49 |
50 |
51 | You may download the [APK](https://github.com/alexmercerind/moving-letters-android/files/13639901/app-release.zip) quick trial.
52 |
53 | The [source-code of the example application](https://github.com/alexmercerind/moving-letters-android/tree/main/app/src/main/java/com/alexmercerind/example) provides more details.
54 |
55 | ## Inspiration
56 |
57 | [Moving Letters for Web / JavaScript](https://tobiasahlin.com/moving-letters/) by [@tobiasahlin](https://twitter.com/tobiasahlin).
58 |
59 | I wanted to implement it in Jetpack Compose!
60 |
61 | ## License
62 |
63 | Copyright © 2023 & onwards, Hitesh Kumar Saini.
64 |
65 | This project & the work under this repository is governed by MIT license that can be found in the [LICENSE](./LICENSE) file.
66 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | id("org.jetbrains.kotlin.android")
4 | }
5 |
6 | android {
7 | namespace = "com.alexmercerind.example"
8 | compileSdk = 34
9 |
10 | defaultConfig {
11 | applicationId = "com.alexmercerind.example"
12 | minSdk = 21
13 | targetSdk = 34
14 | versionCode = 1
15 | versionName = "1.0"
16 |
17 | vectorDrawables {
18 | useSupportLibrary = true
19 | }
20 | }
21 |
22 | buildTypes {
23 | release {
24 | isMinifyEnabled = false
25 | proguardFiles(
26 | getDefaultProguardFile("proguard-android-optimize.txt"),
27 | "proguard-rules.pro"
28 | )
29 | signingConfig = signingConfigs.getByName("debug")
30 | }
31 | }
32 | compileOptions {
33 | sourceCompatibility = JavaVersion.VERSION_1_8
34 | targetCompatibility = JavaVersion.VERSION_1_8
35 | }
36 | kotlinOptions {
37 | jvmTarget = "1.8"
38 | }
39 | buildFeatures {
40 | compose = true
41 | }
42 | composeOptions {
43 | kotlinCompilerExtensionVersion = "1.4.3"
44 | }
45 | packaging {
46 | resources {
47 | excludes += "/META-INF/{AL2.0,LGPL2.1}"
48 | }
49 | }
50 | }
51 |
52 | dependencies {
53 |
54 | implementation("androidx.core:core-ktx:1.12.0")
55 | implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
56 | implementation("androidx.activity:activity-compose:1.8.1")
57 | implementation(platform("androidx.compose:compose-bom:2023.03.00"))
58 | implementation("androidx.compose.ui:ui")
59 | implementation("androidx.compose.ui:ui-graphics")
60 | implementation("androidx.compose.ui:ui-tooling-preview")
61 | implementation("androidx.compose.material3:material3:1.2.0-alpha12")
62 | implementation("androidx.navigation:navigation-compose:2.7.5")
63 | debugImplementation("androidx.compose.ui:ui-tooling")
64 | debugImplementation("androidx.compose.ui:ui-test-manifest")
65 | implementation(project(":moving-letters"))
66 | }
67 |
--------------------------------------------------------------------------------
/app/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk17
3 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
15 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/com/alexmercerind/example/AnimatedTextScreen.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.example
2 |
3 | import androidx.compose.foundation.layout.Arrangement
4 | import androidx.compose.foundation.layout.PaddingValues
5 | import androidx.compose.foundation.layout.Row
6 | import androidx.compose.foundation.layout.Spacer
7 | import androidx.compose.foundation.layout.calculateEndPadding
8 | import androidx.compose.foundation.layout.calculateStartPadding
9 | import androidx.compose.foundation.layout.fillMaxSize
10 | import androidx.compose.foundation.layout.height
11 | import androidx.compose.foundation.layout.padding
12 | import androidx.compose.foundation.layout.width
13 | import androidx.compose.foundation.lazy.LazyColumn
14 | import androidx.compose.foundation.lazy.LazyRow
15 | import androidx.compose.material.icons.Icons
16 | import androidx.compose.material.icons.filled.PlayArrow
17 | import androidx.compose.material.icons.filled.Refresh
18 | import androidx.compose.material3.CardDefaults
19 | import androidx.compose.material3.ElevatedCard
20 | import androidx.compose.material3.HorizontalDivider
21 | import androidx.compose.material3.Icon
22 | import androidx.compose.material3.IconButton
23 | import androidx.compose.material3.MaterialTheme
24 | import androidx.compose.material3.Scaffold
25 | import androidx.compose.material3.Text
26 | import androidx.compose.material3.VerticalDivider
27 | import androidx.compose.runtime.Composable
28 | import androidx.compose.runtime.LaunchedEffect
29 | import androidx.compose.runtime.collectAsState
30 | import androidx.compose.runtime.getValue
31 | import androidx.compose.ui.Alignment
32 | import androidx.compose.ui.Modifier
33 | import androidx.compose.ui.graphics.Color
34 | import androidx.compose.ui.platform.LocalLayoutDirection
35 | import androidx.compose.ui.res.painterResource
36 | import androidx.compose.ui.res.stringResource
37 | import androidx.compose.ui.text.font.FontFamily
38 | import androidx.compose.ui.text.style.TextAlign
39 | import androidx.compose.ui.unit.dp
40 | import com.alexmercerind.movingletters.AnimatedTextState
41 | import com.alexmercerind.movingletters.rememberAnimatedTextState
42 | import kotlinx.coroutines.Dispatchers
43 | import kotlinx.coroutines.delay
44 |
45 | @Composable
46 | fun AnimatedTextScreen(
47 | name: String,
48 | content: @Composable (state: AnimatedTextState, text: String) -> Unit,
49 | contentColor: Color,
50 | containerColor: Color
51 | ) {
52 | Scaffold(
53 | contentColor = contentColor, containerColor = containerColor
54 | ) { padding ->
55 | val text = stringResource(id = R.string.text)
56 | val state = rememberAnimatedTextState()
57 |
58 | LaunchedEffect("AnimatedTextScreen", Dispatchers.IO) {
59 | delay(200L)
60 | state.start()
61 | }
62 |
63 | LazyColumn(
64 | modifier = Modifier.fillMaxSize(),
65 | contentPadding = PaddingValues(
66 | top = padding.calculateTopPadding() + 32.dp,
67 | bottom = padding.calculateBottomPadding() + 32.dp,
68 | end = padding.calculateEndPadding(LocalLayoutDirection.current) + 32.dp,
69 | start = padding.calculateStartPadding(LocalLayoutDirection.current) + 32.dp
70 | )
71 | ) {
72 | item {
73 | content(state, text)
74 | }
75 | item {
76 | Spacer(modifier = Modifier.height(32.dp))
77 | }
78 | item {
79 | Row(
80 | horizontalArrangement = Arrangement.Start,
81 | verticalAlignment = Alignment.CenterVertically
82 | ) {
83 | IconButton(onClick = state::start) {
84 | Icon(
85 | imageVector = Icons.Default.Refresh,
86 | contentDescription = stringResource(id = R.string.start)
87 | )
88 | }
89 | Spacer(modifier = Modifier.width(8.dp))
90 | IconButton(onClick = state::stop) {
91 | Icon(
92 | painter = painterResource(id = R.drawable.baseline_stop_24),
93 | contentDescription = stringResource(id = R.string.stop)
94 | )
95 | }
96 | Spacer(modifier = Modifier.width(8.dp))
97 | IconButton(onClick = state::resume) {
98 | Icon(
99 | imageVector = Icons.Default.PlayArrow,
100 | contentDescription = stringResource(id = R.string.resume)
101 | )
102 | }
103 | Spacer(modifier = Modifier.width(8.dp))
104 | IconButton(onClick = state::pause) {
105 | Icon(
106 | painter = painterResource(id = R.drawable.baseline_pause_24),
107 | contentDescription = stringResource(id = R.string.pause)
108 | )
109 | }
110 | }
111 | }
112 | item {
113 | Spacer(modifier = Modifier.height(32.dp))
114 | }
115 | item {
116 | ElevatedCard(
117 | colors = CardDefaults.cardColors(
118 | containerColor = Color(0xFFFFFFFF), contentColor = Color(0xFF000000)
119 | ), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
120 | ) {
121 | Row(
122 | horizontalArrangement = Arrangement.Start,
123 | verticalAlignment = Alignment.CenterVertically,
124 | modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
125 | ) {
126 | Icon(
127 | painter = painterResource(id = R.drawable.baseline_code_24),
128 | contentDescription = stringResource(id = R.string.code)
129 | )
130 | Spacer(modifier = Modifier.width(16.dp))
131 | Text(
132 | text = stringResource(id = R.string.code),
133 | style = MaterialTheme.typography.titleMedium
134 | )
135 | }
136 | HorizontalDivider()
137 | LazyRow(contentPadding = PaddingValues(16.dp)) {
138 | item {
139 | Text(
140 | text = listOf(
141 | "$name(", " text = \"$text\"", ")"
142 | ).joinToString("\n"),
143 | style = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace)
144 | )
145 | }
146 | }
147 | }
148 | }
149 | item {
150 | Spacer(modifier = Modifier.height(32.dp))
151 | }
152 | item {
153 | val playing by state.playing.collectAsState(false)
154 | val ongoing by state.ongoing.collectAsState(false)
155 | val paused by state.paused.collectAsState(false)
156 | val stopped by state.stopped.collectAsState(false)
157 | ElevatedCard(
158 | colors = CardDefaults.cardColors(
159 | containerColor = Color(0xFFFFFFFF), contentColor = Color(0xFF000000)
160 | ), elevation = CardDefaults.cardElevation(defaultElevation = 2.dp)
161 | ) {
162 | Row(
163 | horizontalArrangement = Arrangement.Start,
164 | verticalAlignment = Alignment.CenterVertically,
165 | modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp)
166 | ) {
167 | Icon(
168 | painter = painterResource(id = R.drawable.baseline_shutter_speed_24),
169 | contentDescription = stringResource(id = R.string.state)
170 | )
171 | Spacer(modifier = Modifier.width(16.dp))
172 | Text(
173 | text = stringResource(id = R.string.state),
174 | style = MaterialTheme.typography.titleMedium
175 | )
176 | }
177 | HorizontalDivider()
178 | mapOf(
179 | "PLAYING" to playing,
180 | "ONGOING" to ongoing,
181 | "PAUSED" to paused,
182 | "STOPPED" to stopped
183 | ).forEach {
184 | Row(
185 | modifier = Modifier.padding(vertical = 8.dp),
186 | verticalAlignment = Alignment.CenterVertically
187 | ) {
188 | Text(
189 | modifier = Modifier.weight(1.0F),
190 | text = it.key,
191 | textAlign = TextAlign.Center,
192 | style = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace)
193 | )
194 | VerticalDivider()
195 | Text(
196 | modifier = Modifier.weight(1.0F),
197 | text = it.value.toString().uppercase(),
198 | textAlign = TextAlign.Center,
199 | style = MaterialTheme.typography.bodyMedium.copy(fontFamily = FontFamily.Monospace)
200 | )
201 | }
202 | }
203 | }
204 | }
205 | item {
206 | Spacer(modifier = Modifier.height(32.dp))
207 | }
208 | }
209 | }
210 | }
211 |
--------------------------------------------------------------------------------
/app/src/main/java/com/alexmercerind/example/Destinations.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.example
2 |
3 | interface Destinations {
4 | val value: String
5 |
6 | object Home: Destinations {
7 | override val value = "Home"
8 | }
9 |
10 | object Effect1: Destinations {
11 | override val value = "Effect1"
12 | }
13 |
14 | object Effect2: Destinations {
15 | override val value = "Effect2"
16 | }
17 |
18 | object Effect3: Destinations {
19 | override val value = "Effect3"
20 | }
21 |
22 | object Effect4: Destinations {
23 | override val value = "Effect4"
24 | }
25 |
26 | object Effect5: Destinations {
27 | override val value = "Effect5"
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/app/src/main/java/com/alexmercerind/example/HomeScreen.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.example
2 |
3 | import android.content.Intent
4 | import android.net.Uri
5 | import androidx.compose.foundation.clickable
6 | import androidx.compose.foundation.layout.fillMaxSize
7 | import androidx.compose.foundation.layout.padding
8 | import androidx.compose.foundation.layout.size
9 | import androidx.compose.foundation.layout.wrapContentSize
10 | import androidx.compose.foundation.lazy.LazyColumn
11 | import androidx.compose.foundation.shape.CircleShape
12 | import androidx.compose.material3.ExperimentalMaterial3Api
13 | import androidx.compose.material3.Icon
14 | import androidx.compose.material3.IconButton
15 | import androidx.compose.material3.LargeTopAppBar
16 | import androidx.compose.material3.ListItem
17 | import androidx.compose.material3.ListItemDefaults
18 | import androidx.compose.material3.Scaffold
19 | import androidx.compose.material3.Surface
20 | import androidx.compose.material3.Text
21 | import androidx.compose.material3.TopAppBarDefaults
22 | import androidx.compose.material3.rememberTopAppBarState
23 | import androidx.compose.runtime.Composable
24 | import androidx.compose.ui.Alignment
25 | import androidx.compose.ui.Modifier
26 | import androidx.compose.ui.draw.clip
27 | import androidx.compose.ui.draw.clipToBounds
28 | import androidx.compose.ui.graphics.Color
29 | import androidx.compose.ui.input.nestedscroll.nestedScroll
30 | import androidx.compose.ui.platform.LocalContext
31 | import androidx.compose.ui.res.painterResource
32 | import androidx.compose.ui.res.stringResource
33 | import androidx.compose.ui.unit.dp
34 | import androidx.navigation.NavController
35 |
36 | @OptIn(ExperimentalMaterial3Api::class)
37 | @Composable
38 | fun HomeScreen(
39 | navController: NavController,
40 | effects: Map>
41 | ) {
42 |
43 | val topAppBarState = rememberTopAppBarState()
44 | val scrollBehavior = TopAppBarDefaults.exitUntilCollapsedScrollBehavior(
45 | state = topAppBarState,
46 | snapAnimationSpec = null
47 | )
48 | Scaffold(
49 | containerColor = Color.Black,
50 | topBar = {
51 | LargeTopAppBar(
52 | title = { Text(text = stringResource(id = R.string.app_name)) },
53 | scrollBehavior = scrollBehavior,
54 | colors = TopAppBarDefaults.largeTopAppBarColors(
55 | containerColor = Color.Black,
56 | titleContentColor = Color.White,
57 | scrolledContainerColor = Color.Black,
58 | actionIconContentColor = Color.White
59 | ),
60 | actions = {
61 | val context = LocalContext.current
62 | IconButton(
63 | onClick = {
64 | val intent = Intent(
65 | Intent.ACTION_VIEW,
66 | Uri.parse("https://github.com/alexmercerind/moving-letters-android")
67 | )
68 | context.startActivity(intent)
69 | }
70 | ) {
71 | Icon(
72 | painter = painterResource(id = R.drawable.github),
73 | contentDescription = stringResource(id = R.string.github)
74 | )
75 | }
76 | }
77 | )
78 | }
79 | ) { padding ->
80 | LazyColumn(
81 | modifier = Modifier
82 | .fillMaxSize()
83 | .padding(padding)
84 | .nestedScroll(scrollBehavior.nestedScrollConnection)
85 | ) {
86 | val list = effects.entries.withIndex().toList()
87 | for (i in list) {
88 | item {
89 | ListItem(
90 | modifier = Modifier.clickable {
91 | navController.navigate(list[i.index].value.key.value)
92 | },
93 | leadingContent = {
94 | Surface(
95 | modifier = Modifier
96 | .size(32.dp)
97 | .clip(CircleShape)
98 | .clipToBounds(),
99 | contentColor = Color.Black
100 | ) {
101 | Text(
102 | modifier = Modifier.wrapContentSize(Alignment.Center),
103 | text = (i.index + 1).toString()
104 | )
105 | }
106 | },
107 | headlineContent = {
108 | Text(text = stringResource(R.string.effect, i.index + 1))
109 | },
110 | colors = ListItemDefaults.colors(
111 | headlineColor = list[i.index].value.value.first,
112 | containerColor = list[i.index].value.value.second,
113 | )
114 | )
115 | }
116 | }
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/app/src/main/java/com/alexmercerind/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.example
2 |
3 | import android.os.Bundle
4 | import androidx.activity.ComponentActivity
5 | import androidx.activity.SystemBarStyle
6 | import androidx.activity.compose.setContent
7 | import androidx.activity.enableEdgeToEdge
8 | import androidx.compose.material3.MaterialTheme
9 | import androidx.compose.ui.graphics.Color
10 | import androidx.compose.ui.text.font.FontWeight
11 | import androidx.navigation.compose.NavHost
12 | import androidx.navigation.compose.composable
13 | import androidx.navigation.compose.rememberNavController
14 | import com.alexmercerind.movingletters.FadeAnimatedText
15 | import com.alexmercerind.movingletters.JumpAnimatedText
16 | import com.alexmercerind.movingletters.RotateAnimatedText
17 | import com.alexmercerind.movingletters.ScaleInAnimatedText
18 | import com.alexmercerind.movingletters.ScaleOutAnimatedText
19 |
20 | class MainActivity : ComponentActivity() {
21 | override fun onCreate(savedInstanceState: Bundle?) {
22 | super.onCreate(savedInstanceState)
23 | enableEdgeToEdge(statusBarStyle = SystemBarStyle.dark(resources.getColor(R.color.transparent)))
24 | setContent {
25 | MaterialTheme {
26 | val navController = rememberNavController()
27 |
28 | NavHost(
29 | navController = navController,
30 | startDestination = Destinations.Home.value
31 | ) {
32 | composable(Destinations.Home.value) {
33 | HomeScreen(
34 | navController = navController,
35 | effects = mapOf(
36 | Destinations.Effect1 to (Color(0xFFFFFFFF) to Color(0xFF9CA4B5)),
37 | Destinations.Effect2 to (Color(0xFFFFFFFF) to Color(0xFFE7C3B9)),
38 | Destinations.Effect3 to (Color(0xFFFFFFFF) to Color(0xFF234A54)),
39 | Destinations.Effect4 to (Color(0xFFFFFFFF) to Color(0xFFC1605D)),
40 | Destinations.Effect5 to (Color(0xFFFFFFFF) to Color(0xFF46373C))
41 | )
42 | )
43 | }
44 | composable(Destinations.Effect1.value) {
45 | AnimatedTextScreen(
46 | name = "ScaleInAnimatedText",
47 | content = { state, text ->
48 | ScaleInAnimatedText(
49 | state = state,
50 | text = text,
51 | style = MaterialTheme.typography.displayLarge.copy(fontWeight = FontWeight.Black),
52 | animateOnMount = false
53 | )
54 | },
55 | contentColor = Color(0xFFFFFFFF),
56 | containerColor = Color(0xFF9CA4B5)
57 | )
58 | }
59 | composable(Destinations.Effect2.value) {
60 | AnimatedTextScreen(
61 | name = "ScaleOutAnimatedText",
62 | content = { state, text ->
63 | ScaleOutAnimatedText(
64 | state = state,
65 | text = text,
66 | style = MaterialTheme.typography.displayLarge.copy(fontWeight = FontWeight.Black),
67 | animateOnMount = false
68 | )
69 | },
70 | contentColor = Color(0xFFFFFFFF),
71 | containerColor = Color(0xFFE7C3B9)
72 | )
73 | }
74 | composable(Destinations.Effect3.value) {
75 | AnimatedTextScreen(
76 | name = "FadeAnimatedText",
77 | content = { state, text ->
78 | FadeAnimatedText(
79 | state = state,
80 | text = text,
81 | style = MaterialTheme.typography.displayLarge.copy(fontWeight = FontWeight.Black),
82 | animateOnMount = false
83 | )
84 | },
85 | contentColor = Color(0xFFFFFFFF),
86 | containerColor = Color(0xFF234A54)
87 | )
88 | }
89 | composable(Destinations.Effect4.value) {
90 | AnimatedTextScreen(
91 | name = "JumpAnimatedText",
92 | content = { state, text ->
93 | JumpAnimatedText(
94 | state = state,
95 | text = text,
96 | style = MaterialTheme.typography.displayLarge.copy(fontWeight = FontWeight.Black),
97 | animateOnMount = false
98 | )
99 | },
100 | contentColor = Color(0xFFFFFFFF),
101 | containerColor = Color(0xFFC1605D)
102 | )
103 | }
104 | composable(Destinations.Effect5.value) {
105 | AnimatedTextScreen(
106 | name = "RotateAnimatedText",
107 | content = { state, text ->
108 | RotateAnimatedText(
109 | state = state,
110 | text = text,
111 | style = MaterialTheme.typography.displayLarge.copy(fontWeight = FontWeight.Black),
112 | animateOnMount = false
113 | )
114 | },
115 | contentColor = Color(0xFFFFFFFF),
116 | containerColor = Color(0xFF46373C)
117 | )
118 | }
119 | }
120 | }
121 | }
122 | }
123 | }
124 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_code_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_pause_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_shutter_speed_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/baseline_stop_24.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/github.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-hdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-mdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-xhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #00000000
4 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Moving Letters
3 | Code
4 | Effect %1$d
5 | GitHub
6 | Pause
7 | Resume
8 | Start
9 | State
10 | Stop
11 | The quick brown fox jumps over the lazy dog!
12 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_rules.xml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
13 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/data_extraction_rules.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
12 |
13 |
19 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 | plugins {
3 | id("com.android.application") version "8.1.1" apply false
4 | id("org.jetbrains.kotlin.android") version "1.8.10" apply false
5 | id("com.android.library") version "8.1.1" apply false
6 | id("maven-publish")
7 | }
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Tue Dec 05 22:19:36 IST 2023
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
5 | zipStoreBase=GRADLE_USER_HOME
6 | zipStorePath=wrapper/dists
7 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/moving-letters/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/moving-letters/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.library")
3 | id("org.jetbrains.kotlin.android")
4 | id("maven-publish")
5 | }
6 |
7 | android {
8 | namespace = "com.alexmercerind.movingletters"
9 | compileSdk = 33
10 |
11 | defaultConfig {
12 | minSdk = 21
13 |
14 | consumerProguardFiles("consumer-rules.pro")
15 | }
16 |
17 | buildTypes {
18 | release {
19 | isMinifyEnabled = false
20 | proguardFiles(
21 | getDefaultProguardFile("proguard-android-optimize.txt"),
22 | "proguard-rules.pro"
23 | )
24 | }
25 | }
26 | compileOptions {
27 | sourceCompatibility = JavaVersion.VERSION_1_8
28 | targetCompatibility = JavaVersion.VERSION_1_8
29 | }
30 | kotlinOptions {
31 | jvmTarget = "1.8"
32 | }
33 | buildFeatures {
34 | compose = true
35 | }
36 | composeOptions {
37 | kotlinCompilerExtensionVersion = "1.4.3"
38 | }
39 | publishing {
40 | singleVariant("release") {
41 | withSourcesJar()
42 | withJavadocJar()
43 | }
44 | }
45 | }
46 |
47 | dependencies {
48 | implementation("androidx.core:core-ktx:1.12.0")
49 | implementation("androidx.appcompat:appcompat:1.6.1")
50 | implementation("com.google.android.material:material:1.10.0")
51 | implementation(platform("androidx.compose:compose-bom:2023.03.00"))
52 | implementation("androidx.compose.ui:ui")
53 | implementation("androidx.compose.ui:ui-graphics")
54 | implementation("androidx.compose.ui:ui-tooling-preview")
55 | implementation("androidx.compose.material3:material3")
56 | }
57 |
58 | publishing {
59 | publications {
60 | register("release") {
61 | groupId = "alexmercerind"
62 | artifactId = "moving-letters"
63 | version = "1.0.0"
64 | afterEvaluate {
65 | from(components["release"])
66 | }
67 | }
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/moving-letters/consumer-rules.pro:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/alexmercerind/moving-letters-android/f732395178e09fe3c59f11a4d7af314d88ae63b6/moving-letters/consumer-rules.pro
--------------------------------------------------------------------------------
/moving-letters/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
--------------------------------------------------------------------------------
/moving-letters/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/moving-letters/src/main/java/com/alexmercerind/movingletters/AnimatedTextState.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.movingletters
2 |
3 | import androidx.compose.animation.core.Easing
4 | import androidx.compose.runtime.Composable
5 | import androidx.compose.runtime.MutableState
6 | import androidx.compose.runtime.getValue
7 | import androidx.compose.runtime.mutableStateOf
8 | import androidx.compose.runtime.remember
9 | import androidx.compose.runtime.setValue
10 | import androidx.compose.ui.graphics.TransformOrigin
11 | import androidx.compose.ui.text.TextStyle
12 | import kotlinx.coroutines.CompletableDeferred
13 | import kotlinx.coroutines.DelicateCoroutinesApi
14 | import kotlinx.coroutines.Dispatchers
15 | import kotlinx.coroutines.GlobalScope
16 | import kotlinx.coroutines.Job
17 | import kotlinx.coroutines.async
18 | import kotlinx.coroutines.delay
19 | import kotlinx.coroutines.flow.MutableStateFlow
20 | import kotlinx.coroutines.flow.StateFlow
21 | import kotlinx.coroutines.flow.map
22 | import kotlinx.coroutines.flow.update
23 | import kotlinx.coroutines.isActive
24 | import kotlinx.coroutines.launch
25 | import kotlin.time.Duration
26 |
27 | /**
28 | * A state object that can be hoisted to control and observe the animated text state.
29 | * In most cases, this state will be created via [rememberAnimatedTextState].
30 | */
31 | @OptIn(DelicateCoroutinesApi::class)
32 | class AnimatedTextState() {
33 | /** Whether animation is currently paused. */
34 | val paused: StateFlow get() = _paused
35 |
36 | /** Whether animation is currently stopped. */
37 | val stopped: StateFlow get() = _stopped
38 |
39 | /** Whether animation is currently playing (not paused). */
40 | val playing get() = paused.map { !it }
41 |
42 | /** Whether animation is currently ongoing (not stopped). */
43 | val ongoing get() = stopped.map { !it }
44 |
45 | /** Whether this instance is attached to an animated text. */
46 | internal var attached = false
47 |
48 | /** Whether initial text layout has been done. */
49 | internal val layout = CompletableDeferred()
50 |
51 | /** Current visible character index. */
52 | internal var current by mutableStateOf(-1)
53 |
54 | /** Current animation coroutine job. */
55 | private var job: Job? = null
56 |
57 | /** Current animation coroutine jobs. */
58 | private var jobs: MutableSet = mutableSetOf()
59 |
60 | private var _paused = MutableStateFlow(true)
61 | private var _stopped = MutableStateFlow(true)
62 |
63 | private var _visibility: List>? = null
64 | private var _lineHeight: MutableList? = null
65 | private var _transformOrigin: MutableList? = null
66 |
67 | private var _animationDuration: Duration? = null
68 | private var _intermediateDuration: Duration? = null
69 |
70 | internal var visibility: List>
71 | get() = _visibility!!
72 | set(value) {
73 | _visibility = value
74 | }
75 | internal var lineHeight: MutableList
76 | get() = _lineHeight!!
77 | set(value) {
78 | _lineHeight = value
79 | }
80 | internal var transformOrigin: MutableList
81 | get() = _transformOrigin!!
82 | set(value) {
83 | _transformOrigin = value
84 | }
85 | internal var animationDuration: Duration
86 | get() = _animationDuration!!
87 | set(value) {
88 | _animationDuration = value
89 | }
90 | internal var intermediateDuration: Duration
91 | get() = _intermediateDuration!!
92 | set(value) {
93 | _intermediateDuration = value
94 | }
95 |
96 | fun start() {
97 | stop()
98 | resume()
99 | _stopped.update { false }
100 | }
101 |
102 | fun stop() {
103 | pause()
104 | current = -1
105 | for (i in visibility.indices) {
106 | visibility[i].value = false
107 | }
108 | _stopped.update { true }
109 | }
110 |
111 | fun resume() {
112 | if (paused.value) {
113 | job = GlobalScope.launch(Dispatchers.IO) {
114 | layout.await()
115 | for (i in current.coerceIn(0, 1 shl 16) until visibility.size) {
116 | if (coroutineContext.isActive) {
117 | delay(intermediateDuration)
118 | visibility[i].value = true
119 | jobs.add(
120 | async {
121 | delay(animationDuration)
122 | current = i
123 | delay(100)
124 | visibility[i].value = false
125 |
126 | if (current == visibility.size - 1) {
127 | _stopped.update { true }
128 | }
129 | }
130 | )
131 | }
132 | }
133 | }
134 | _paused.update { false }
135 | }
136 | }
137 |
138 | fun pause() {
139 | if (!paused.value) {
140 | job?.cancel()
141 | job = null
142 | jobs.forEach { it.cancel() }
143 | jobs.clear()
144 | _paused.update { true }
145 | }
146 | }
147 | }
148 |
149 |
150 | /**
151 | * Creates a [AnimatedTextState] that is remembered across compositions.
152 | */
153 | @Composable
154 | fun rememberAnimatedTextState() = remember { AnimatedTextState() }
155 |
--------------------------------------------------------------------------------
/moving-letters/src/main/java/com/alexmercerind/movingletters/FadeAnimatedText.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.movingletters
2 |
3 | import androidx.compose.animation.AnimatedVisibility
4 | import androidx.compose.animation.core.EaseInOut
5 | import androidx.compose.animation.core.Easing
6 | import androidx.compose.animation.core.FiniteAnimationSpec
7 | import androidx.compose.animation.core.tween
8 | import androidx.compose.animation.fadeIn
9 | import androidx.compose.animation.fadeOut
10 | import androidx.compose.foundation.layout.Box
11 | import androidx.compose.material3.LocalTextStyle
12 | import androidx.compose.material3.Text
13 | import androidx.compose.runtime.Composable
14 | import androidx.compose.runtime.LaunchedEffect
15 | import androidx.compose.runtime.mutableStateOf
16 | import androidx.compose.ui.Modifier
17 | import androidx.compose.ui.draw.clipToBounds
18 | import androidx.compose.ui.graphics.Color
19 | import androidx.compose.ui.graphics.TransformOrigin
20 | import androidx.compose.ui.text.TextStyle
21 | import androidx.compose.ui.text.buildAnnotatedString
22 | import kotlinx.coroutines.Dispatchers
23 | import kotlin.time.Duration
24 | import kotlin.time.Duration.Companion.milliseconds
25 | import kotlin.time.DurationUnit
26 |
27 | @Composable
28 | fun FadeAnimatedText(
29 | modifier: Modifier = Modifier,
30 | state: AnimatedTextState? = null,
31 | text: String,
32 | style: TextStyle? = null,
33 | easing: Easing = EaseInOut,
34 | animationDuration: Duration = 300.milliseconds,
35 | intermediateDuration: Duration = 50.milliseconds,
36 | animateOnMount: Boolean = true
37 | ) {
38 | val animationSpec: FiniteAnimationSpec =
39 | tween(animationDuration.toDouble(DurationUnit.MILLISECONDS).toInt(), 0, easing)
40 |
41 | val currentStyle = style ?: LocalTextStyle.current
42 | val currentState = state ?: rememberAnimatedTextState()
43 | if (!currentState.attached) {
44 | currentState.attached = true
45 |
46 | currentState.visibility = text.map { mutableStateOf(false) }
47 | currentState.lineHeight = text.map { 0.0F }.toMutableList()
48 | currentState.transformOrigin = text.map { TransformOrigin.Center }.toMutableList()
49 |
50 | currentState.animationDuration = animationDuration
51 | currentState.intermediateDuration = intermediateDuration
52 | }
53 |
54 | LaunchedEffect("FadeAnimatedText", Dispatchers.IO) {
55 | if (animateOnMount) {
56 | currentState.start()
57 | }
58 | }
59 |
60 | Box(modifier = modifier.clipToBounds()) {
61 | Text(
62 | text = text,
63 | style = currentStyle.copy(color = Color.Transparent),
64 | onTextLayout = {
65 | for (offset in text.indices) {
66 | val x = it.multiParagraph.getBoundingBox(offset).width / 2 + it.multiParagraph.getHorizontalPosition(offset, true)
67 | var y = 0.0F
68 | val line = it.multiParagraph.getLineForOffset(offset)
69 | for (i in 0..line) {
70 | y += if (i == line) it.multiParagraph.getLineHeight(i) / 2 else it.multiParagraph.getLineHeight(i)
71 | }
72 | currentState.transformOrigin[offset] = TransformOrigin(
73 | x / it.multiParagraph.width,
74 | y / it.multiParagraph.height
75 | )
76 | currentState.lineHeight[offset] = it.multiParagraph.getLineHeight(line)
77 | }
78 | currentState.layout.complete(Any())
79 | }
80 | )
81 | if (currentState.current >= 0) {
82 | Text(
83 | text = buildAnnotatedString {
84 | addStyle(currentStyle.toSpanStyle(), 0, currentState.current)
85 | addStyle(currentStyle.copy(color = Color.Transparent).toSpanStyle(), currentState.current + 1, text.length)
86 | append(text)
87 | },
88 | style = currentStyle,
89 | )
90 | }
91 | for (i in text.indices) {
92 | AnimatedVisibility(
93 | visible = currentState.visibility[i].value,
94 | enter = fadeIn(animationSpec = animationSpec),
95 | exit = fadeOut(animationSpec = tween(0))
96 | ) {
97 | Text(
98 | text = buildAnnotatedString {
99 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), 0, i)
100 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), i + 1, text.length)
101 | append(text)
102 | },
103 | style = currentStyle,
104 | )
105 | }
106 | }
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/moving-letters/src/main/java/com/alexmercerind/movingletters/JumpAnimatedText.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.movingletters
2 |
3 | import androidx.compose.animation.AnimatedVisibility
4 | import androidx.compose.animation.core.FiniteAnimationSpec
5 | import androidx.compose.animation.core.Spring.DampingRatioMediumBouncy
6 | import androidx.compose.animation.core.Spring.StiffnessMediumLow
7 | import androidx.compose.animation.core.spring
8 | import androidx.compose.animation.core.tween
9 | import androidx.compose.animation.fadeOut
10 | import androidx.compose.animation.slideInVertically
11 | import androidx.compose.foundation.layout.Box
12 | import androidx.compose.material3.LocalTextStyle
13 | import androidx.compose.material3.Text
14 | import androidx.compose.runtime.Composable
15 | import androidx.compose.runtime.LaunchedEffect
16 | import androidx.compose.runtime.mutableStateOf
17 | import androidx.compose.ui.Modifier
18 | import androidx.compose.ui.draw.clipToBounds
19 | import androidx.compose.ui.graphics.Color
20 | import androidx.compose.ui.graphics.TransformOrigin
21 | import androidx.compose.ui.text.TextStyle
22 | import androidx.compose.ui.text.buildAnnotatedString
23 | import androidx.compose.ui.unit.IntOffset
24 | import kotlinx.coroutines.Dispatchers
25 | import kotlin.time.Duration
26 | import kotlin.time.Duration.Companion.milliseconds
27 |
28 | @Composable
29 | fun JumpAnimatedText(
30 | modifier: Modifier = Modifier,
31 | state: AnimatedTextState? = null,
32 | text: String,
33 | style: TextStyle? = null,
34 | dampingRatio: Float = DampingRatioMediumBouncy,
35 | stiffness: Float = StiffnessMediumLow,
36 | intermediateDuration: Duration = 80.milliseconds,
37 | animateOnMount: Boolean = true
38 | ) {
39 | val animationSpec: FiniteAnimationSpec = spring(dampingRatio, stiffness)
40 |
41 | val currentStyle = style ?: LocalTextStyle.current
42 | val currentState = state ?: rememberAnimatedTextState()
43 | if (!currentState.attached) {
44 | currentState.attached = true
45 |
46 | currentState.visibility = text.map { mutableStateOf(false) }
47 | currentState.lineHeight = text.map { 0.0F }.toMutableList()
48 | currentState.transformOrigin = text.map { TransformOrigin.Center }.toMutableList()
49 |
50 | currentState.animationDuration = 2000.milliseconds
51 | currentState.intermediateDuration = intermediateDuration
52 | }
53 |
54 | LaunchedEffect("JumpAnimatedText", Dispatchers.IO) {
55 | if (animateOnMount) {
56 | currentState.start()
57 | }
58 | }
59 |
60 | Box(modifier = modifier.clipToBounds()) {
61 | Text(
62 | text = text,
63 | style = currentStyle.copy(color = Color.Transparent),
64 | onTextLayout = {
65 | for (offset in text.indices) {
66 | val x = it.multiParagraph.getBoundingBox(offset).width / 2 + it.multiParagraph.getHorizontalPosition(offset, true)
67 | var y = 0.0F
68 | val line = it.multiParagraph.getLineForOffset(offset)
69 | for (i in 0..line) {
70 | y += if (i == line) it.multiParagraph.getLineHeight(i) / 2 else it.multiParagraph.getLineHeight(i)
71 | }
72 | currentState.transformOrigin[offset] = TransformOrigin(
73 | x / it.multiParagraph.width,
74 | y / it.multiParagraph.height
75 | )
76 | currentState.lineHeight[offset] = it.multiParagraph.getLineHeight(line)
77 | }
78 | currentState.layout.complete(Any())
79 | }
80 | )
81 | if (currentState.current >= 0) {
82 | Text(
83 | text = buildAnnotatedString {
84 | addStyle(currentStyle.toSpanStyle(), 0, currentState.current)
85 | addStyle(currentStyle.copy(color = Color.Transparent).toSpanStyle(), currentState.current + 1, text.length)
86 | append(text)
87 | },
88 | style = currentStyle,
89 | )
90 | }
91 | for (i in text.indices) {
92 | AnimatedVisibility(
93 | visible = currentState.visibility[i].value,
94 | enter = slideInVertically(
95 | animationSpec = animationSpec,
96 | initialOffsetY = {
97 | (0.5F * currentState.lineHeight[i]).toInt()
98 | }
99 | ),
100 | exit = fadeOut(animationSpec = tween(0))
101 | ) {
102 | Text(
103 | text = buildAnnotatedString {
104 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), 0, i)
105 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), i + 1, text.length)
106 | append(text)
107 | },
108 | style = currentStyle,
109 | )
110 | }
111 | }
112 | }
113 | }
114 |
--------------------------------------------------------------------------------
/moving-letters/src/main/java/com/alexmercerind/movingletters/RotateAnimatedText.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.movingletters
2 |
3 | import androidx.compose.animation.core.EaseOut
4 | import androidx.compose.animation.core.Easing
5 | import androidx.compose.animation.core.FiniteAnimationSpec
6 | import androidx.compose.animation.core.animateFloat
7 | import androidx.compose.animation.core.tween
8 | import androidx.compose.animation.core.updateTransition
9 | import androidx.compose.foundation.layout.Box
10 | import androidx.compose.material3.LocalTextStyle
11 | import androidx.compose.material3.Text
12 | import androidx.compose.runtime.Composable
13 | import androidx.compose.runtime.LaunchedEffect
14 | import androidx.compose.runtime.getValue
15 | import androidx.compose.runtime.mutableStateOf
16 | import androidx.compose.runtime.remember
17 | import androidx.compose.runtime.setValue
18 | import androidx.compose.ui.Modifier
19 | import androidx.compose.ui.draw.alpha
20 | import androidx.compose.ui.draw.clipToBounds
21 | import androidx.compose.ui.graphics.Color
22 | import androidx.compose.ui.graphics.TransformOrigin
23 | import androidx.compose.ui.graphics.graphicsLayer
24 | import androidx.compose.ui.text.TextStyle
25 | import androidx.compose.ui.text.buildAnnotatedString
26 | import kotlinx.coroutines.Dispatchers
27 | import kotlin.time.Duration
28 | import kotlin.time.Duration.Companion.milliseconds
29 | import kotlin.time.DurationUnit
30 |
31 | @Composable
32 | fun RotateAnimatedText(
33 | modifier: Modifier = Modifier,
34 | state: AnimatedTextState? = null,
35 | text: String,
36 | style: TextStyle? = null,
37 | easing: Easing = EaseOut,
38 | animationDuration: Duration = 300.milliseconds,
39 | intermediateDuration: Duration = 50.milliseconds,
40 | animateOnMount: Boolean = true
41 | ) {
42 | val animationSpec: FiniteAnimationSpec =
43 | tween(animationDuration.toDouble(DurationUnit.MILLISECONDS).toInt(), 0, easing)
44 |
45 | val currentStyle = style ?: LocalTextStyle.current
46 | val currentState = state ?: rememberAnimatedTextState()
47 | if (!currentState.attached) {
48 | currentState.attached = true
49 |
50 | currentState.visibility = text.map { mutableStateOf(false) }
51 | currentState.lineHeight = text.map { 0.0F }.toMutableList()
52 | currentState.transformOrigin = text.map { TransformOrigin.Center }.toMutableList()
53 |
54 | currentState.animationDuration = animationDuration
55 | currentState.intermediateDuration = intermediateDuration
56 | }
57 |
58 | LaunchedEffect("RotateAnimatedText", Dispatchers.IO) {
59 | if (animateOnMount) {
60 | currentState.start()
61 | }
62 | }
63 |
64 | Box(modifier = modifier.clipToBounds()) {
65 | Text(
66 | text = text,
67 | style = currentStyle.copy(color = Color.Transparent),
68 | onTextLayout = {
69 | for (offset in text.indices) {
70 | val x = it.multiParagraph.getBoundingBox(offset).left
71 | var y = 0.0F
72 | val line = it.multiParagraph.getLineForOffset(offset)
73 | for (i in 0..line) {
74 | y += it.multiParagraph.getLineHeight(i)
75 | }
76 | currentState.transformOrigin[offset] = TransformOrigin(
77 | x / it.multiParagraph.width,
78 | y / it.multiParagraph.height
79 | )
80 | currentState.lineHeight[offset] = it.multiParagraph.getLineHeight(line)
81 | }
82 | currentState.layout.complete(Any())
83 | }
84 | )
85 | if (currentState.current >= 0) {
86 | Text(
87 | text = buildAnnotatedString {
88 | addStyle(currentStyle.toSpanStyle(), 0, currentState.current)
89 | addStyle(
90 | currentStyle.copy(color = Color.Transparent).toSpanStyle(),
91 | currentState.current + 1,
92 | text.length
93 | )
94 | append(text)
95 | },
96 | style = currentStyle,
97 | )
98 | }
99 | for (i in text.indices) {
100 | if (currentState.visibility[i].value) {
101 | RotatedContent(
102 | animationSpec = animationSpec,
103 | transformOrigin = currentState.transformOrigin[i]
104 | ) {
105 | Text(
106 | text = buildAnnotatedString {
107 | addStyle(
108 | currentStyle.toSpanStyle().copy(color = Color.Transparent),
109 | 0,
110 | i
111 | )
112 | addStyle(
113 | currentStyle.toSpanStyle().copy(color = Color.Transparent),
114 | i + 1,
115 | text.length
116 | )
117 | append(text)
118 | },
119 | style = currentStyle,
120 | )
121 | }
122 | }
123 | }
124 | }
125 | }
126 |
127 | @Composable
128 | fun RotatedContent(
129 | animationSpec: FiniteAnimationSpec,
130 | transformOrigin: TransformOrigin,
131 | content: @Composable () -> Unit
132 | ) {
133 |
134 | // animate*AsState(targetValue = *)
135 | // updateTransition(*)
136 |
137 | var reset by remember { mutableStateOf(false) }
138 |
139 | val transition = updateTransition(reset, label = "RotatedContent::transition")
140 |
141 | val alpha by transition.animateFloat(
142 | label = "RotatedContent::alpha",
143 | transitionSpec = { animationSpec },
144 | targetValueByState = {
145 | if (it) 1.0F else 0.0F
146 | }
147 | )
148 | val rotationZ by transition.animateFloat(
149 | label = "RotatedContent::rotationZ",
150 | transitionSpec = { animationSpec },
151 | targetValueByState = {
152 | if (it) 0.0F else 45.0F
153 | }
154 | )
155 |
156 | LaunchedEffect("RotatedContent::LaunchedEffect", Dispatchers.IO) {
157 | reset = true
158 | }
159 |
160 | Box(
161 | modifier = Modifier
162 | .alpha(alpha)
163 | // The .rotate modifier does not allow transform origin.
164 | .graphicsLayer(
165 | rotationZ = rotationZ,
166 | transformOrigin = transformOrigin
167 | )
168 | ) {
169 | content()
170 | }
171 | }
172 |
--------------------------------------------------------------------------------
/moving-letters/src/main/java/com/alexmercerind/movingletters/ScaleInAnimatedText.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.movingletters
2 |
3 | import androidx.compose.animation.AnimatedVisibility
4 | import androidx.compose.animation.ExperimentalAnimationApi
5 | import androidx.compose.animation.core.EaseInOut
6 | import androidx.compose.animation.core.Easing
7 | import androidx.compose.animation.core.FiniteAnimationSpec
8 | import androidx.compose.animation.core.tween
9 | import androidx.compose.animation.fadeIn
10 | import androidx.compose.animation.fadeOut
11 | import androidx.compose.animation.scaleIn
12 | import androidx.compose.foundation.layout.Box
13 | import androidx.compose.material3.LocalTextStyle
14 | import androidx.compose.material3.Text
15 | import androidx.compose.runtime.Composable
16 | import androidx.compose.runtime.LaunchedEffect
17 | import androidx.compose.runtime.mutableStateOf
18 | import androidx.compose.ui.Modifier
19 | import androidx.compose.ui.draw.clipToBounds
20 | import androidx.compose.ui.graphics.Color
21 | import androidx.compose.ui.graphics.TransformOrigin
22 | import androidx.compose.ui.text.TextStyle
23 | import androidx.compose.ui.text.buildAnnotatedString
24 | import kotlinx.coroutines.Dispatchers
25 | import kotlin.time.Duration
26 | import kotlin.time.Duration.Companion.milliseconds
27 | import kotlin.time.DurationUnit
28 |
29 | @OptIn(ExperimentalAnimationApi::class)
30 | @Composable
31 | fun ScaleInAnimatedText(
32 | modifier: Modifier = Modifier,
33 | state: AnimatedTextState? = null,
34 | text: String,
35 | style: TextStyle? = null,
36 | easing: Easing = EaseInOut,
37 | animationDuration: Duration = 300.milliseconds,
38 | intermediateDuration: Duration = 50.milliseconds,
39 | animateOnMount: Boolean = true
40 | ) {
41 | val animationSpec: FiniteAnimationSpec =
42 | tween(animationDuration.toDouble(DurationUnit.MILLISECONDS).toInt(), 0, easing)
43 |
44 | val currentStyle = style ?: LocalTextStyle.current
45 | val currentState = state ?: rememberAnimatedTextState()
46 | if (!currentState.attached) {
47 | currentState.attached = true
48 |
49 | currentState.visibility = text.map { mutableStateOf(false) }
50 | currentState.lineHeight = text.map { 0.0F }.toMutableList()
51 | currentState.transformOrigin = text.map { TransformOrigin.Center }.toMutableList()
52 |
53 | currentState.animationDuration = animationDuration
54 | currentState.intermediateDuration = intermediateDuration
55 | }
56 |
57 | LaunchedEffect("ScaleInAnimatedText", Dispatchers.IO) {
58 | if (animateOnMount) {
59 | currentState.start()
60 | }
61 | }
62 |
63 | Box(modifier = modifier.clipToBounds()) {
64 | Text(
65 | text = text,
66 | style = currentStyle.copy(color = Color.Transparent),
67 | onTextLayout = {
68 | for (offset in text.indices) {
69 | val x = it.multiParagraph.getBoundingBox(offset).width / 2 + it.multiParagraph.getHorizontalPosition(offset, true)
70 | var y = 0.0F
71 | val line = it.multiParagraph.getLineForOffset(offset)
72 | for (i in 0..line) {
73 | y += if (i == line) it.multiParagraph.getLineHeight(i) / 2 else it.multiParagraph.getLineHeight(i)
74 | }
75 | currentState.transformOrigin[offset] = TransformOrigin(
76 | x / it.multiParagraph.width,
77 | y / it.multiParagraph.height
78 | )
79 | currentState.lineHeight[offset] = it.multiParagraph.getLineHeight(line)
80 | }
81 | currentState.layout.complete(Any())
82 | }
83 | )
84 | if (currentState.current >= 0) {
85 | Text(
86 | text = buildAnnotatedString {
87 | addStyle(currentStyle.toSpanStyle(), 0, currentState.current)
88 | addStyle(currentStyle.copy(color = Color.Transparent).toSpanStyle(), currentState.current + 1, text.length)
89 | append(text)
90 | },
91 | style = currentStyle,
92 | )
93 | }
94 | for (i in text.indices) {
95 | AnimatedVisibility(
96 | visible = currentState.visibility[i].value,
97 | enter = scaleIn(transformOrigin = currentState.transformOrigin[i], animationSpec = animationSpec) + fadeIn(animationSpec = animationSpec),
98 | exit = fadeOut(animationSpec = tween(0))
99 | ) {
100 | Text(
101 | text = buildAnnotatedString {
102 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), 0, i)
103 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), i + 1, text.length)
104 | append(text)
105 | },
106 | style = currentStyle,
107 | )
108 | }
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/moving-letters/src/main/java/com/alexmercerind/movingletters/ScaleOutAnimatedText.kt:
--------------------------------------------------------------------------------
1 | package com.alexmercerind.movingletters
2 |
3 | import androidx.compose.animation.AnimatedVisibility
4 | import androidx.compose.animation.ExperimentalAnimationApi
5 | import androidx.compose.animation.core.EaseInOut
6 | import androidx.compose.animation.core.Easing
7 | import androidx.compose.animation.core.FiniteAnimationSpec
8 | import androidx.compose.animation.core.tween
9 | import androidx.compose.animation.fadeIn
10 | import androidx.compose.animation.fadeOut
11 | import androidx.compose.animation.scaleIn
12 | import androidx.compose.foundation.layout.Box
13 | import androidx.compose.material3.LocalTextStyle
14 | import androidx.compose.material3.Text
15 | import androidx.compose.runtime.Composable
16 | import androidx.compose.runtime.LaunchedEffect
17 | import androidx.compose.runtime.mutableStateOf
18 | import androidx.compose.ui.Modifier
19 | import androidx.compose.ui.draw.clipToBounds
20 | import androidx.compose.ui.graphics.Color
21 | import androidx.compose.ui.graphics.TransformOrigin
22 | import androidx.compose.ui.text.TextStyle
23 | import androidx.compose.ui.text.buildAnnotatedString
24 | import kotlinx.coroutines.Dispatchers
25 | import kotlin.time.Duration
26 | import kotlin.time.Duration.Companion.milliseconds
27 | import kotlin.time.DurationUnit
28 |
29 | @OptIn(ExperimentalAnimationApi::class)
30 | @Composable
31 | fun ScaleOutAnimatedText(
32 | modifier: Modifier = Modifier,
33 | state: AnimatedTextState? = null,
34 | text: String,
35 | style: TextStyle? = null,
36 | easing: Easing = EaseInOut,
37 | animationDuration: Duration = 300.milliseconds,
38 | intermediateDuration: Duration = 50.milliseconds,
39 | animateOnMount: Boolean = true
40 | ) {
41 | val animationSpec: FiniteAnimationSpec =
42 | tween(animationDuration.toDouble(DurationUnit.MILLISECONDS).toInt(), 0, easing)
43 |
44 | val currentStyle = style ?: LocalTextStyle.current
45 | val currentState = state ?: rememberAnimatedTextState()
46 | if (!currentState.attached) {
47 | currentState.attached = true
48 |
49 | currentState.visibility = text.map { mutableStateOf(false) }
50 | currentState.lineHeight = text.map { 0.0F }.toMutableList()
51 | currentState.transformOrigin = text.map { TransformOrigin.Center }.toMutableList()
52 |
53 | currentState.animationDuration = animationDuration
54 | currentState.intermediateDuration = intermediateDuration
55 | }
56 |
57 | LaunchedEffect("ScaleOutAnimatedText", Dispatchers.IO) {
58 | if (animateOnMount) {
59 | currentState.start()
60 | }
61 | }
62 |
63 | Box(modifier = modifier.clipToBounds()) {
64 | Text(
65 | text = text,
66 | style = currentStyle.copy(color = Color.Transparent),
67 | onTextLayout = {
68 | for (offset in text.indices) {
69 | val x = it.multiParagraph.getBoundingBox(offset).width / 2 + it.multiParagraph.getHorizontalPosition(offset, true)
70 | var y = 0.0F
71 | val line = it.multiParagraph.getLineForOffset(offset)
72 | for (i in 0..line) {
73 | y += if (i == line) it.multiParagraph.getLineHeight(i) / 2 else it.multiParagraph.getLineHeight(i)
74 | }
75 | currentState.transformOrigin[offset] = TransformOrigin(
76 | x / it.multiParagraph.width,
77 | y / it.multiParagraph.height
78 | )
79 | currentState.lineHeight[offset] = it.multiParagraph.getLineHeight(line)
80 | }
81 | currentState.layout.complete(Any())
82 | }
83 | )
84 | if (currentState.current >= 0) {
85 | Text(
86 | text = buildAnnotatedString {
87 | addStyle(currentStyle.toSpanStyle(), 0, currentState.current)
88 | addStyle(currentStyle.copy(color = Color.Transparent).toSpanStyle(), currentState.current + 1, text.length)
89 | append(text)
90 | },
91 | style = currentStyle,
92 | )
93 | }
94 | for (i in text.indices) {
95 | AnimatedVisibility(
96 | visible = currentState.visibility[i].value,
97 | enter = scaleIn(transformOrigin = currentState.transformOrigin[i], animationSpec = animationSpec, initialScale = 2.0F) + fadeIn(animationSpec = animationSpec),
98 | exit = fadeOut(animationSpec = tween(0))
99 | ) {
100 | Text(
101 | text = buildAnnotatedString {
102 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), 0, i)
103 | addStyle(currentStyle.toSpanStyle().copy(color = Color.Transparent), i + 1, text.length)
104 | append(text)
105 | },
106 | style = currentStyle,
107 | )
108 | }
109 | }
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/settings.gradle.kts:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | google()
4 | mavenCentral()
5 | gradlePluginPortal()
6 | }
7 | }
8 | dependencyResolutionManagement {
9 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
10 | repositories {
11 | google()
12 | mavenCentral()
13 | }
14 | }
15 |
16 | rootProject.name = "Moving Letters Example"
17 | include(":app")
18 | include(":moving-letters")
19 |
--------------------------------------------------------------------------------