Skip to content

Commit fe4182c

Browse files
committed
Fix scroll bug
1 parent 707d3a0 commit fe4182c

File tree

5 files changed

+18
-3
lines changed

5 files changed

+18
-3
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
android:exported="true"
1818
android:label="@string/app_name"
1919
android:theme="@style/Theme.Sample"
20+
android:windowSoftInputMode="adjustResize"
2021
>
2122
<intent-filter>
2223
<action android:name="android.intent.action.MAIN" />

app/src/main/java/jp/kaleidot725/sample/MainActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import jp.kaleidot725.sample.ui.theme.DemoText
1010
class MainActivity : ComponentActivity() {
1111
override fun onCreate(savedInstanceState: Bundle?) {
1212
super.onCreate(savedInstanceState)
13-
WindowCompat.setDecorFitsSystemWindows(window, false)
1413
setContent { Demo(DemoText) }
1514
}
1615
}

app/src/main/java/jp/kaleidot725/sample/ui/composable/Demo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import androidx.compose.foundation.layout.fillMaxSize
1111
import androidx.compose.foundation.layout.fillMaxWidth
1212
import androidx.compose.foundation.layout.height
1313
import androidx.compose.foundation.layout.ime
14+
import androidx.compose.foundation.layout.imePadding
1415
import androidx.compose.foundation.layout.padding
1516
import androidx.compose.foundation.layout.size
1617
import androidx.compose.foundation.layout.systemBarsPadding

texteditor/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ afterEvaluate {
6464
from components.release
6565
groupId = 'com.github.kaleidot725'
6666
artifactId = 'text-editor-compose'
67-
version = '0.4.1'
67+
version = '0.5.0'
6868
}
6969
}
7070
}

texteditor/src/main/java/jp/kaleidot725/texteditor/view/TextEditor.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import androidx.compose.foundation.clickable
44
import androidx.compose.foundation.interaction.MutableInteractionSource
55
import androidx.compose.foundation.layout.Box
66
import androidx.compose.foundation.layout.PaddingValues
7+
import androidx.compose.foundation.layout.Spacer
8+
import androidx.compose.foundation.layout.height
9+
import androidx.compose.foundation.layout.padding
710
import androidx.compose.foundation.lazy.LazyColumn
811
import androidx.compose.foundation.lazy.itemsIndexed
912
import androidx.compose.foundation.lazy.rememberLazyListState
@@ -17,6 +20,7 @@ import androidx.compose.runtime.rememberUpdatedState
1720
import androidx.compose.runtime.setValue
1821
import androidx.compose.ui.Modifier
1922
import androidx.compose.ui.focus.FocusRequester
23+
import androidx.compose.ui.unit.dp
2024
import jp.kaleidot725.texteditor.controller.rememberTextEditorController
2125
import jp.kaleidot725.texteditor.state.TextEditorState
2226
import java.util.Date
@@ -43,7 +47,13 @@ fun TextEditor(
4347
editableController.syncState(textEditorState)
4448

4549
LaunchedEffect(lastScrollEvent) {
46-
lastScrollEvent?.index?.let { lazyColumnState.animateScrollToItem(it) }
50+
lastScrollEvent?.index?.let { index ->
51+
val first = lazyColumnState.layoutInfo.visibleItemsInfo.minBy { it.index }.index
52+
val end = lazyColumnState.layoutInfo.visibleItemsInfo.maxBy { it.index }.index
53+
if (index < first || end < index) {
54+
lazyColumnState.animateScrollToItem(index)
55+
}
56+
}
4757
}
4858

4959
LazyColumn(
@@ -127,6 +137,10 @@ fun TextEditor(
127137
}
128138
)
129139
}
140+
141+
item {
142+
Spacer(modifier = Modifier.height(100.dp))
143+
}
130144
}
131145
}
132146

0 commit comments

Comments
 (0)