Skip to content

Commit

Permalink
Fix for crash (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
brunoblazincdecode authored and tarikyasar committed Jun 6, 2024
1 parent 2b8098b commit 36e1ed3
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 19 deletions.
14 changes: 8 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
buildscript {
ext {
compose = '1.6.7'
compose = '1.7.0-alpha08'
composeActivity = '1.9.0'

ktxCore = '1.10.1'
ktxLifeCycle = '2.6.1'
ktxCore = '1.12.0'
ktxLifeCycle = '2.6.2'

material = '1.6.7'
kotlinCompilerExtension = '1.5.4'
}
}
plugins {
id 'com.android.application' version '7.0.4' apply false
id 'com.android.library' version '7.0.4' apply false
id 'org.jetbrains.kotlin.android' version '1.9.0' apply false
id 'com.android.application' version '8.1.2' apply false
id 'com.android.library' version '8.1.2' apply false
id 'org.jetbrains.kotlin.android' version '1.9.20' apply false
id("com.google.gms.google-services") version "4.3.15" apply false
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
}

allprojects {
apply plugin: "org.jlleitschuh.gradle.ktlint"

}
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Apr 03 21:34:42 TRT 2023
#Fri May 24 14:46:06 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion ohteepee/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.5.1'
kotlinCompilerExtensionVersion "$kotlinCompilerExtension"
}
}

Expand Down
33 changes: 26 additions & 7 deletions ohteepee/src/main/java/com/composeuisuite/ohteepee/OhTeePeeCell.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -78,12 +79,24 @@ internal fun OhTeePeeCell(
val placeHolderTextStyle = remember(cellConfiguration.placeHolderTextStyle) {
cellConfiguration.placeHolderTextStyle.copy(textAlign = TextAlign.Center)
}
val textFieldValue = remember(value) {
TextFieldValue(
text = value,
selection = TextRange(value.length),
)
// Holds the latest internal TextFieldValue state. We need to keep it to have the correct value
// of the composition.
var textFieldValueState by remember { mutableStateOf(TextFieldValue(text = value)) }
// Holds the latest TextFieldValue that BasicTextField was recomposed with. We couldn't simply
// pass `TextFieldValue(text = value)` to the CoreTextField because we need to preserve the
// composition.
val textFieldValue = textFieldValueState.copy(text = value, selection = TextRange(value.length))

SideEffect {
if (textFieldValue.selection != textFieldValueState.selection ||
textFieldValue.composition != textFieldValueState.composition) {
textFieldValueState = textFieldValue
}
}
// Last String value that either text field was recomposed with or updated in the onValueChange
// callback. We keep track of it to prevent calling onValueChange(String) for same String when
// CoreTextField's onValueChange is called multiple times without recomposition in between.
var lastTextValue by remember(value) { mutableStateOf(value) }
val borderModifier = if (configurations.enableBottomLine) {
Modifier.drawBehind {
val y = size.height
Expand Down Expand Up @@ -115,8 +128,14 @@ internal fun OhTeePeeCell(
BasicTextField(
value = textFieldValue,
onValueChange = {
if (it.text == value) return@BasicTextField
onValueChange(it.text)
textFieldValueState = it

val stringChangedSinceLastInvocation = lastTextValue != it.text
lastTextValue = it.text

if (stringChangedSinceLastInvocation) {
onValueChange(it.text)
}
},
visualTransformation = visualTransformation,
textStyle = textStyle,
Expand Down
4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ android {
compose true
}
composeOptions {
kotlinCompilerExtensionVersion '1.5.1'
kotlinCompilerExtensionVersion "$kotlinCompilerExtension"
}
packagingOptions {
resources {
Expand All @@ -55,7 +55,7 @@ dependencies {

// Compose
implementation "androidx.activity:activity-compose:$composeActivity"
implementation "androidx.compose.ui:ui:$compose"
implementation "androidx.compose.ui:ui:1.7.0-alpha08"
implementation "androidx.compose.ui:ui-tooling-preview:$compose"

// Material
Expand Down

0 comments on commit 36e1ed3

Please sign in to comment.