@@ -116,6 +116,7 @@ fun RowScope.IconKey(
116116 @DrawableRes drawable : Int ,
117117 key : SpecialKey ,
118118 callback : Lp3KeyboardCallback ,
119+ enableKeyAnimation : Boolean ,
119120 modifier : Modifier = Modifier ,
120121 width : Dp = STANDARD_KEY_WIDTH_DP .dp
121122) {
@@ -138,19 +139,25 @@ fun RowScope.IconKey(
138139 painterResource(drawable),
139140 contentDescription = " TODO" ,
140141 tint = LocalKeyboardColors .current.foreground,
141- modifier = Modifier .graphicsLayer {
142- val isPressed = pressed // state read happens at draw time
143- scaleX = if (isPressed) 1.25f else 1f
144- scaleY = if (isPressed) 1.25f else 1f
145- translationY = if (isPressed) - 12 .dp.toPx() else 0f
146- }
142+ modifier = Modifier .then(
143+ if (enableKeyAnimation) {
144+ Modifier .graphicsLayer {
145+ val isPressed = pressed
146+ scaleX = if (isPressed) 1.25f else 1f
147+ scaleY = if (isPressed) 1.25f else 1f
148+ translationY = if (isPressed) - 12 .dp.toPx() else 0f
149+ }
150+ } else {
151+ Modifier
152+ }
153+ )
147154 )
148155 }
149156}
150157
151158
152159@Composable
153- fun RowScope.SpaceBar (callback : Lp3KeyboardCallback , width : Dp ) {
160+ fun RowScope.SpaceBar (callback : Lp3KeyboardCallback , width : Dp , enableKeyAnimation : Boolean ) {
154161 var pressed by remember { mutableStateOf(false ) }
155162 Box (
156163 Modifier
@@ -163,13 +170,18 @@ fun RowScope.SpaceBar(callback: Lp3KeyboardCallback, width: Dp) {
163170 onReleased = { callback.onSpecialKeyReleased(SpecialKey .Space ) },
164171 onLongPressed = { callback.onSpecialKeyLongPressed(SpecialKey .Space ) },
165172 onPressedChanged = { pressed = it }
173+ ).then(
174+ if (enableKeyAnimation) {
175+ Modifier .graphicsLayer {
176+ val isPressed = pressed
177+ scaleX = if (isPressed) 1.1f else 1f
178+ scaleY = if (isPressed) 1.1f else 1f
179+ translationY = if (isPressed) - 8 .dp.toPx() else 0f
180+ }
181+ } else {
182+ Modifier
183+ }
166184 )
167- .graphicsLayer {
168- val isPressed = pressed // state read happens at draw time
169- scaleX = if (isPressed) 1.1f else 1f
170- scaleY = if (isPressed) 1.1f else 1f
171- translationY = if (isPressed) - 8 .dp.toPx() else 0f
172- }
173185 ) {
174186 Box (
175187 Modifier
@@ -185,13 +197,15 @@ fun RowScope.SpaceBar(callback: Lp3KeyboardCallback, width: Dp) {
185197fun RowScope.Key (
186198 char : Char ,
187199 callback : Lp3KeyboardCallback ,
200+ enableKeyAnimation : Boolean ,
188201 override : SpecialKey ? = null
189- ) = Key (char.code, callback, override )
202+ ) = Key (char.code, callback, enableKeyAnimation, override )
190203
191204@Composable
192205fun RowScope.Key (
193206 code : Int ,
194207 callback : Lp3KeyboardCallback ,
208+ enableKeyAnimation : Boolean ,
195209 override : SpecialKey ? = null,
196210 width : Dp = STANDARD_KEY_WIDTH_DP .dp
197211) {
@@ -228,12 +242,18 @@ fun RowScope.Key(
228242 fontFamily = akkuratFamily,
229243 fontWeight = FontWeight .Normal ,
230244 fontSize = STANDARD_KEY_TEXT_SP .sp,
231- modifier = Modifier .graphicsLayer {
232- val isPressed = pressed // state read happens at draw time
233- scaleX = if (isPressed) 1.25f else 1f
234- scaleY = if (isPressed) 1.25f else 1f
235- translationY = if (isPressed) - 12 .dp.toPx() else 0f
236- }
245+ modifier = Modifier .then(
246+ if (enableKeyAnimation) {
247+ Modifier .graphicsLayer {
248+ val isPressed = pressed
249+ scaleX = if (isPressed) 1.25f else 1f
250+ scaleY = if (isPressed) 1.25f else 1f
251+ translationY = if (isPressed) - 12 .dp.toPx() else 0f
252+ }
253+ } else {
254+ Modifier
255+ }
256+ )
237257 )
238258 }
239259}
@@ -242,7 +262,8 @@ fun RowScope.Key(
242262fun RowScope.MultiLabelKey (
243263 labelText : String ,
244264 key : SpecialKey ,
245- callback : Lp3KeyboardCallback
265+ callback : Lp3KeyboardCallback ,
266+ enableKeyAnimation : Boolean
246267) {
247268 var pressed by remember { mutableStateOf(false ) }
248269 Box (
@@ -266,12 +287,18 @@ fun RowScope.MultiLabelKey(
266287 letterSpacing = 2 .sp,
267288 fontSize = 16 .sp,
268289 textAlign = TextAlign .Center ,
269- modifier = Modifier .graphicsLayer {
270- val isPressed = pressed // state read happens at draw time
271- scaleX = if (isPressed) 1.25f else 1f
272- scaleY = if (isPressed) 1.25f else 1f
273- translationY = if (isPressed) - 12 .dp.toPx() else 0f
274- }
290+ modifier = Modifier .then(
291+ if (enableKeyAnimation) {
292+ Modifier .graphicsLayer {
293+ val isPressed = pressed // state read happens at draw time
294+ scaleX = if (isPressed) 1.25f else 1f
295+ scaleY = if (isPressed) 1.25f else 1f
296+ translationY = if (isPressed) - 12 .dp.toPx() else 0f
297+ }
298+ } else {
299+ Modifier
300+ }
301+ )
275302 )
276303 }
277304}
@@ -280,9 +307,13 @@ typealias Emoji = Int
280307
281308data class KeyboardOptions (
282309 val emojis : List <Emoji >? ,
283- val displayClose : Boolean ,
284310 val displayReturn : Boolean ,
285- val displayVoice : Boolean
311+ val displayVoice : Boolean ,
312+ val enableKeyAnimation : Boolean
313+ )
314+
315+ data class LayoutOptions (
316+ val displayCloseButton : Boolean
286317)
287318
288319@Composable
@@ -301,24 +332,25 @@ fun ColumnScope.DefaultRow(
301332
302333
303334@Composable
304- fun ColumnScope.FirstRow (characters : String , callback : Lp3KeyboardCallback ) {
335+ fun ColumnScope.FirstRow (characters : String , callback : Lp3KeyboardCallback , enableKeyAnimation : Boolean ) {
305336 DefaultRow {
306337 for (char in characters) {
307- Key (char, callback)
338+ Key (char, callback, enableKeyAnimation )
308339 }
309340 }
310341}
311342
312343@Composable
313- fun ColumnScope.SecondRow (characters : String , callback : Lp3KeyboardCallback ) {
344+ fun ColumnScope.SecondRow (characters : String , callback : Lp3KeyboardCallback , enableKeyAnimation : Boolean ) {
314345 // same style as first row on all keyboards
315- FirstRow (characters, callback)
346+ FirstRow (characters, callback, enableKeyAnimation )
316347}
317348
318349@Composable
319350fun ColumnScope.ThirdRow (
320351 characters : String ,
321352 callback : Lp3KeyboardCallback ,
353+ keyboardOptions : KeyboardOptions ,
322354 leftButton : @Composable RowScope .() -> Unit
323355) {
324356 DefaultRow {
@@ -328,7 +360,7 @@ fun ColumnScope.ThirdRow(
328360 Spacer (Modifier .width(MEDIUM_KEY_WIDTH_DP .dp))
329361 }
330362 for (char in characters) {
331- Key (char, callback)
363+ Key (char, callback, keyboardOptions.enableKeyAnimation )
332364 }
333365 if (characters.length == 5 ) {
334366 Spacer (Modifier .width(STANDARD_KEY_WIDTH_DP .dp))
@@ -337,6 +369,7 @@ fun ColumnScope.ThirdRow(
337369 R .drawable.back_lp3,
338370 SpecialKey .Backspace ,
339371 callback,
372+ keyboardOptions.enableKeyAnimation,
340373 width = ICON_KEY_WIDTH_DP .dp,
341374 modifier = Modifier .padding(10 .dp).padding(start = 8 .dp, bottom = 6 .dp)
342375 )
@@ -363,18 +396,20 @@ fun ColumnScope.FinalRow(
363396 R .drawable.smile,
364397 SpecialKey .Emojis ,
365398 callback,
399+ options.enableKeyAnimation,
366400 width = iconKeyWidth.dp,
367401 modifier = Modifier .padding(start = 5 .dp, end = 6.5 .dp).padding(end = 16 .dp)
368402 )
369403 } else {
370404 Spacer (Modifier .width(iconKeyWidth.dp))
371405 }
372- SpaceBar (callback, 160 .dp)
406+ SpaceBar (callback, 160 .dp, options.enableKeyAnimation )
373407 if (options.displayReturn) {
374408 IconKey (
375409 R .drawable.return_lp3,
376410 SpecialKey .Return ,
377411 callback,
412+ options.enableKeyAnimation,
378413 width = iconKeyWidth.dp,
379414 modifier = Modifier .padding(top = 4 .dp, start = 20 .dp, end = 0 .dp)
380415 )
@@ -387,6 +422,7 @@ fun ColumnScope.FinalRow(
387422 R .drawable.microphone_lp3,
388423 SpecialKey .Voice ,
389424 callback,
425+ options.enableKeyAnimation,
390426 width = iconKeyWidth.dp,
391427 modifier = Modifier .padding(top = 2 .dp, start = 12 .dp, end = 4 .dp)
392428 )
@@ -410,8 +446,13 @@ internal val previewCallback = object : Lp3KeyboardCallback {
410446fun Lp3KeyboardDarkPreview () {
411447 Lp3KeyboardTheme (DarkKeyboardColors ) {
412448 Column (verticalArrangement = Arrangement .Bottom , modifier = Modifier .fillMaxSize()) {
413- val options = KeyboardOptions (defaultEmojis, true , true , true )
414- Lp3KeyboardWrapper (EmojiLayout , options, previewCallback)
449+ val keyboardOptions = KeyboardOptions (defaultEmojis,
450+ displayReturn = true ,
451+ displayVoice = true ,
452+ enableKeyAnimation = true
453+ )
454+ val layoutOptions = LayoutOptions (displayCloseButton = true )
455+ Lp3KeyboardWrapper (EmojiLayout , keyboardOptions, layoutOptions, previewCallback)
415456 }
416457 }
417458}
@@ -421,8 +462,13 @@ fun Lp3KeyboardDarkPreview() {
421462fun Lp3KeyboardLightPreview () {
422463 Lp3KeyboardTheme (LightKeyboardColors ) {
423464 Column (verticalArrangement = Arrangement .Bottom , modifier = Modifier .fillMaxSize()) {
424- val options = KeyboardOptions (defaultEmojis, true , true , true )
425- Lp3KeyboardWrapper (UpperCaseLayout , options, previewCallback)
465+ val keyboardOptions = KeyboardOptions (defaultEmojis,
466+ displayReturn = true ,
467+ displayVoice = true ,
468+ enableKeyAnimation = true
469+ )
470+ val layoutOptions = LayoutOptions (displayCloseButton = true )
471+ Lp3KeyboardWrapper (UpperCaseLayout , keyboardOptions, layoutOptions, previewCallback)
426472 }
427473 }
428474}
0 commit comments