Skip to content

Commit fb2452d

Browse files
authored
Code edit text (#14)
* Created working text field * Added code suggestions * Bumped versions to comply with kotlin 1.9.10 * Added tab with spaces replacement * Added theme to desktop example * Updated highlights and improved desktop example * Bumped highlights version * Completed example with new CodeEditText * Updated web example * Removed material3 and corrected android example * Created CodeEditText for ios * Corrected highlights export * Small code suggestions * Prepared readme and changelog * Corrected readme * Reverted ios changes
1 parent d3333e5 commit fb2452d

File tree

21 files changed

+750
-294
lines changed

21 files changed

+750
-294
lines changed

.run/iosExample.run.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<component name="ProjectRunConfigurationManager">
2-
<configuration default="false" name="iosExample" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="BB27C957-E8E5-4D97-B638-2A8A605B5FF8" XCODE_PROJECT="$PROJECT_DIR$/iosExample/iosExample.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosExample">
2+
<configuration default="false" name="iosExample" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="B9B05138-47D5-41E7-9D91-9C4C4D4A8392" XCODE_PROJECT="$PROJECT_DIR$/iosExample/iosExample.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosExample">
33
<method v="2">
44
<option name="com.jetbrains.kmm.ios.BuildIOSAppTask" enabled="true" />
55
</method>

CHANGELOG.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1+
## [0.6.0]
2+
3+
### Added
4+
5+
- CodeEditText view
6+
- Theme switcher in examples
7+
- Code edit README sample code
8+
9+
### Changed
10+
11+
- Android example
12+
- Desktop example
13+
- Web example
14+
- Highlights library export for iOS framework
15+
- Highlights library version to 0.7.1
16+
17+
### Removed
18+
19+
- Material3 references
20+
121
## [0.5.0]
222

323
### Added
24+
425
- Maven publication
526

627
### Changed
28+
729
- README sections
830
- KodeView dependency import style
931

1032
## [0.4.0]
1133

1234
### Added
35+
1336
- Maven local publication
1437

1538
### Changed
39+
1640
- KodeView import model
1741

1842
## [0.3.1]
1943

2044
### Added
21-
2245
- Web section to README
2346

2447
## [0.3.0]

README.md

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ repositories {
2121
```
2222

2323
```shell
24-
implementation("dev.snipme:kodeview:0.5.0")
24+
implementation("dev.snipme:kodeview:0.6.0")
2525
```
2626

2727
## Features ✨
28-
- CodeTextView UI view
28+
- CodeTextView
29+
- CodeEditText
2930
- Code component analysis (Keyword, comment, etc.)
3031
- Multiple syntax languages (Java, Swift, Kotlin, C, ...)
3132
- Themes
@@ -41,17 +42,15 @@ If you feel that any of our project has saved you a time or effort, then conside
4142
## Components 🧩
4243

4344
### CodeTextView
44-
The basic component that takes instance of Highlights and applies coloring on a text.
45+
Basic component that takes instance of Highlights and applies coloring on a text.
4546

4647
```kotlin
4748
@Composable
4849
fun MyApp() {
4950
val highlights = remember {
5051
mutableStateOf(
5152
Highlights
52-
.default()
53-
.getBuilder()
54-
.code("public static void main(String[] args) {}")
53+
.Builder(code = "public static void main(String[] args) {}")
5554
.build()
5655
)
5756
}
@@ -64,14 +63,47 @@ fun MyApp() {
6463
}
6564
```
6665

66+
### CodeEditText
67+
With this component, you can update your code via `onValueChange` callback.
68+
The Highlights library is ready for incremental updates, so change values anytime.
69+
The view bases on `TextField()`, and all it's fields are available for customization.
70+
71+
```kotlin
72+
@Composable
73+
fun MyApp() {
74+
val highlights = remember {
75+
mutableStateOf(
76+
Highlights
77+
.Builder(code = "public static void main(String[] args) {}")
78+
.build()
79+
)
80+
}
81+
82+
MaterialTheme {
83+
Column {
84+
CodeEditText(
85+
highlights = highlights.value,
86+
onValueChange = { textValue ->
87+
highlights.value = highlights.value.getBuilder()
88+
.code(textValue)
89+
.build()
90+
},
91+
// Customize view's style
92+
colors = TextFieldDefaults.textFieldColors(),
93+
)
94+
}
95+
}
96+
}
97+
```
98+
6799
## Run examples 🏎️
68100

69101
Not all examples can be executed from command line, so recommended way is to use pre-created configurations:
70102

71103
<img width="270" alt="iShot_2023-09-18_08 19 44" src="https://github.com/SnipMeDev/KodeView/assets/8405055/be660f49-5a77-445e-a717-6aaec9b5c28a">
72104

73105
## TODO 🚧
74-
- [ ] CodeEditText
106+
- [X] CodeEditText
75107

76108
## Contribution 💻
77109
Any form of support is very welcomed.

androidExample/build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ plugins {
33
id(libs.plugins.android.application.get().pluginId)
44
alias(libs.plugins.kotlin.android)
55
alias(libs.plugins.ksp) apply false
6+
alias(libs.plugins.compose)
67
}
78

89
android {
@@ -50,12 +51,11 @@ dependencies {
5051
implementation("androidx.core:core-ktx:1.12.0")
5152
implementation("androidx.appcompat:appcompat:1.6.1")
5253
// Compose
53-
val composeBom = platform("androidx.compose:compose-bom:2023.03.00")
54-
implementation(composeBom)
5554
implementation("androidx.activity:activity-compose:1.7.2")
56-
implementation("androidx.compose.material3:material3")
57-
implementation("androidx.compose.ui:ui-tooling-preview")
58-
debugImplementation("androidx.compose.ui:ui-tooling")
59-
debugImplementation("androidx.compose.ui:ui-test-manifest")
55+
implementation(compose.runtime)
56+
implementation(compose.foundation)
57+
implementation(compose.material)
58+
implementation(compose.ui)
59+
implementation(compose.materialIconsExtended)
6060
implementation(libs.kodeview)
6161
}
Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
11
package dev.snipme.androidexample
22

3-
import androidx.compose.foundation.background
43
import androidx.compose.foundation.clickable
5-
import androidx.compose.foundation.layout.Column
64
import androidx.compose.foundation.layout.fillMaxWidth
75
import androidx.compose.foundation.layout.padding
86
import androidx.compose.foundation.shape.RoundedCornerShape
9-
import androidx.compose.material3.DropdownMenu
10-
import androidx.compose.material3.DropdownMenuItem
11-
import androidx.compose.material3.Text
7+
import androidx.compose.material.DropdownMenu
8+
import androidx.compose.material.DropdownMenuItem
9+
import androidx.compose.material.Text
1210
import androidx.compose.runtime.Composable
1311
import androidx.compose.runtime.getValue
1412
import androidx.compose.runtime.mutableStateOf
1513
import androidx.compose.runtime.remember
1614
import androidx.compose.runtime.setValue
1715
import androidx.compose.ui.Modifier
1816
import androidx.compose.ui.draw.clip
19-
import androidx.compose.ui.graphics.Color
2017
import androidx.compose.ui.text.style.TextAlign
2118
import androidx.compose.ui.unit.dp
2219

@@ -33,33 +30,29 @@ fun Dropdown(
3330

3431
var isExpanded by remember { mutableStateOf(false) }
3532

36-
Column(Modifier.padding(16.dp)) {
37-
DropdownMenu(
38-
modifier = Modifier.background(Color.White),
39-
expanded = isExpanded,
40-
onDismissRequest = { isExpanded = false },
41-
) {
42-
options.forEach { option ->
43-
DropdownMenuItem(
44-
modifier = Modifier,
45-
text = { Text(text = option) },
46-
onClick = {
47-
selectedOption = option
48-
onSelect(option)
49-
isExpanded = !isExpanded
50-
},
51-
)
52-
}
33+
DropdownMenu(
34+
expanded = isExpanded,
35+
onDismissRequest = { isExpanded = false },
36+
) {
37+
options.forEach { option ->
38+
DropdownMenuItem(
39+
onClick = {
40+
selectedOption = option
41+
onSelect(option)
42+
isExpanded = !isExpanded
43+
},
44+
) { Text(text = option) }
5345
}
5446

55-
Text(
56-
text = selectedOption,
57-
textAlign = TextAlign.Center,
58-
modifier = modifier
59-
.clip(RoundedCornerShape(16.dp))
60-
.fillMaxWidth()
61-
.clickable { isExpanded = !isExpanded }
62-
.padding(8.dp),
63-
)
6447
}
48+
49+
Text(
50+
text = selectedOption,
51+
textAlign = TextAlign.Center,
52+
modifier = modifier
53+
.clip(RoundedCornerShape(16.dp))
54+
.fillMaxWidth()
55+
.clickable { isExpanded = !isExpanded }
56+
.padding(8.dp),
57+
)
6558
}

0 commit comments

Comments
 (0)