Skip to content

Commit 1faedb5

Browse files
committed
Update README
1 parent ab60e7b commit 1faedb5

File tree

7 files changed

+59
-121
lines changed

7 files changed

+59
-121
lines changed

README.md

Lines changed: 59 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
- [x] Display line number
2424
- [x] Copy multiple line
2525
- [x] Delete multiple line
26-
- [ ] Support physical keyboard
26+
- [x] Support physical keyboard
2727

2828
## Usage
2929

@@ -44,139 +44,85 @@ allprojects {
4444

4545
```groovy
4646
dependencies {
47-
implementation 'com.github.kaleidot725:text-editor-compose:0.2.0'
47+
implementation 'com.github.kaleidot725:text-editor-compose:0.3.0'
4848
}
4949
```
5050

51-
### Step 3: Declare TextEditor & TextEditorState
51+
### Step 3: Change windowSoftInputMode
5252

53-
```kotlin
54-
class MainActivity : ComponentActivity() {
55-
override fun onCreate(savedInstanceState: Bundle?) {
56-
super.onCreate(savedInstanceState)
57-
setContent {
58-
SampleTheme {
59-
val textEditorState by rememberTextEditorState(lines = DemoText.lines())
60-
TextEditor(
61-
textEditorState = textEditorState,
62-
onUpdatedState = { },
63-
modifier = Modifier.fillMaxSize()
64-
)
65-
}
66-
}
67-
}
68-
}
53+
**AndroidManifest.xml**
54+
```
55+
<?xml version="1.0" encoding="utf-8"?>
56+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
57+
xmlns:tools="http://schemas.android.com/tools">
58+
59+
<application
60+
android:allowBackup="true"
61+
android:dataExtractionRules="@xml/data_extraction_rules"
62+
android:fullBackupContent="@xml/backup_rules"
63+
android:icon="@mipmap/ic_launcher"
64+
android:label="@string/app_name"
65+
android:roundIcon="@mipmap/ic_launcher_round"
66+
android:supportsRtl="true"
67+
android:theme="@style/Theme.Sample"
68+
tools:targetApi="31">
69+
<activity
70+
android:name=".MainActivity"
71+
android:exported="true"
72+
android:label="@string/app_name"
73+
android:theme="@style/Theme.Sample"
74+
android:windowSoftInputMode="adjustResize" // !! ADD THIS LINE !!
75+
>
76+
<intent-filter>
77+
<action android:name="android.intent.action.MAIN" />
78+
79+
<category android:name="android.intent.category.LAUNCHER" />
80+
</intent-filter>
81+
</activity>
82+
</application>
83+
84+
</manifest>
6985
```
70-
71-
### Step 4: Customize text fields
7286

7387
```kotlin
7488
class MainActivity : ComponentActivity() {
89+
@OptIn(ExperimentalComposeUiApi::class)
7590
override fun onCreate(savedInstanceState: Bundle?) {
7691
super.onCreate(savedInstanceState)
77-
setContent {
78-
SampleTheme {
79-
val textEditorState by rememberTextEditorState(lines = DemoText.lines())
80-
TextEditor(
81-
textEditorState = textEditorState,
82-
onUpdatedState = { },
83-
modifier = Modifier.fillMaxSize(),
84-
decorationBox = { index, isSelected, innerTextField ->
85-
val backgroundColor = if (isSelected) Color(0x8000ff00) else Color.White
86-
Row(modifier = Modifier.background(backgroundColor)) {
87-
Text(text = (index + 1).toString().padStart(3, '0'))
88-
Spacer(modifier = Modifier.width(4.dp))
89-
innerTextField(modifier = Modifier.fillMaxWidth())
90-
}
91-
}
92-
)
93-
}
94-
}
95-
}
92+
93+
WindowCompat.setDecorFitsSystemWindows(window, false) // !! ADD THIS LINE !!
94+
95+
}
9696
}
9797
```
9898

99-
### Step 5: Create multiple selection menu
99+
### Step 4: Declare TextEditor & TextEditorState
100100

101101
```kotlin
102102
class MainActivity : ComponentActivity() {
103+
@OptIn(ExperimentalComposeUiApi::class)
103104
override fun onCreate(savedInstanceState: Bundle?) {
104105
super.onCreate(savedInstanceState)
106+
107+
WindowCompat.setDecorFitsSystemWindows(window, false)
108+
105109
setContent {
106110
SampleTheme {
107-
val textEditorState by rememberTextEditorState(lines = DemoText.lines())
108-
TextEditor(
109-
textEditorState = textEditorState,
110-
onUpdatedState = { },
111-
modifier = Modifier.fillMaxSize(),
112-
decorationBox = { index, isSelected, innerTextField ->
113-
val backgroundColor = if (isSelected) Color(0x8000ff00) else Color.White
114-
Row(modifier = Modifier.background(backgroundColor)) {
115-
Text(text = (index + 1).toString().padStart(3, '0'))
116-
Spacer(modifier = Modifier.width(4.dp))
117-
innerTextField(modifier = Modifier.fillMaxWidth())
118-
}
119-
}
120-
)
121-
}
122-
}
123-
}
124-
}
125-
126-
@Composable
127-
private fun ColumnScope.TextEditorMenu(textEditorState: TextEditorState) {
128-
val context: Context = LocalContext.current
129-
val clipboardManager: ClipboardManager = LocalClipboardManager.current
130-
131-
Row(modifier = Modifier.padding(8.dp)) {
132-
Text(
133-
text = "Enable multiple selection mode",
134-
modifier = Modifier
135-
.weight(0.9f, true)
136-
.align(Alignment.CenterVertically)
137-
)
138-
Switch(
139-
checked = textEditorState.isMultipleSelectionMode.value,
140-
onCheckedChange = {
141-
textEditorState.enableMultipleSelectionMode(
142-
!textEditorState.isMultipleSelectionMode.value
111+
var textEditorState by remember { mutableStateOf(TextEditorState.create(DemoText)) }
112+
val contentPaddingValues = PaddingValues(
113+
bottom = with(LocalDensity.current) { WindowInsets.ime.getBottom(this).toDp() }
143114
)
144-
}
145-
)
146-
}
147115

148-
Row(modifier = Modifier.padding(8.dp)) {
149-
Text(
150-
text = "Copy selected lines",
151-
modifier = Modifier
152-
.weight(0.9f, true)
153-
.align(Alignment.CenterVertically)
154-
)
155-
Button(
156-
onClick = {
157-
val text = textEditorState.getSelectedText()
158-
textEditorState.enableMultipleSelectionMode(false)
159-
160-
clipboardManager.setText(AnnotatedString(text))
161-
Toast.makeText(context, "Copy selected text to clipboard", Toast.LENGTH_SHORT).show()
116+
Box(modifier = Modifier
117+
.fillMaxSize()
118+
.systemBarsPadding()) {
119+
TextEditor(
120+
textEditorState = textEditorState,
121+
onChanged = { textEditorState = it },
122+
contentPaddingValues = contentPaddingValues,
123+
)
124+
}
162125
}
163-
) {
164-
Text(text = "EXECUTE")
165-
}
166-
}
167-
168-
Row(modifier = Modifier.padding(8.dp)) {
169-
Text(
170-
text = "Delete selected lines",
171-
modifier = Modifier
172-
.weight(0.9f, true)
173-
.align(Alignment.CenterVertically)
174-
)
175-
Button(onClick = {
176-
textEditorState.deleteSelectedLines()
177-
textEditorState.enableMultipleSelectionMode(false)
178-
}) {
179-
Text(text = "EXECUTE")
180126
}
181127
}
182128
}
@@ -192,18 +138,10 @@ private fun ColumnScope.TextEditorMenu(textEditorState: TextEditorState) {
192138

193139
![Insert and delete newline](./docs/2.gif)
194140

195-
### Get selected line index
196-
197-
![Get selected line index](./docs/3.gif)
198-
199-
### Display line number
200-
201-
![Display line number](./docs/4.gif)
202-
203141
### Copy multiple line
204142

205-
![Copy multiple line](./docs/5.gif)
143+
![Copy multiple line](./docs/3.gif)
206144

207145
### Delete multiple line
208146

209-
![Delete multiple line](./docs/6.gif)
147+
![Delete multiple line](./docs/4.gif)

docs/1.gif

-83.5 KB
Loading

docs/2.gif

23 KB
Loading

docs/3.gif

-516 KB
Loading

docs/4.gif

41.7 KB
Loading

docs/5.gif

-58.1 KB
Binary file not shown.

docs/6.gif

-63.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)