Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .run/iosExample.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<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">
<configuration default="false" name="iosExample" type="KmmRunConfiguration" factoryName="iOS Application" CONFIG_VERSION="1" EXEC_TARGET_ID="645C2113-7E25-482E-9F32-B612B7A046E0" XCODE_PROJECT="$PROJECT_DIR$/iosExample/iosExample.xcodeproj" XCODE_CONFIGURATION="Debug" XCODE_SCHEME="iosExample">
<method v="2">
<option name="com.jetbrains.kmm.ios.BuildIOSAppTask" enabled="true" />
</method>
Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## [0.8.0]

### Added
- CodeEditText component for SwiftUI

### Changed
- Kotlin version to 1.9.21
- Material3 CodeEditText location to a material3 subpackage for better distinction
- Highlights naming in iOS project thanks to library export
- iOS example project
- Libs cache to incremental
- Dependency structure to new pattern

## [0.7.0]

### Added
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
![kodeview_banner_opaque](https://github.com/SnipMeDev/KodeView/assets/8405055/59c6a2af-1b32-4a02-998f-ecae2296363a)

[![Maven Central](https://img.shields.io/maven-central/v/dev.snipme/kodeview)](https://mvnrepository.com/artifact/dev.snipme)
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.10-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![Kotlin](https://img.shields.io/badge/kotlin-1.9.21-blue.svg?logo=kotlin)](http://kotlinlang.org)
[![GitHub License](https://img.shields.io/badge/license-Apache%20License%202.0-blue.svg?style=flat)](http://www.apache.org/licenses/LICENSE-2.0)

# KodeView
Expand All @@ -21,7 +21,7 @@ repositories {
```

```shell
implementation("dev.snipme:kodeview:0.7.0")
implementation("dev.snipme:kodeview:0.8.0")
```

## Features ✨
Expand Down
2 changes: 1 addition & 1 deletion androidExample/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
// Compose
implementation("androidx.activity:activity-compose:1.7.2")
implementation("androidx.activity:activity-compose:1.8.2")
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import dev.snipme.highlights.model.SyntaxLanguage
import dev.snipme.highlights.model.SyntaxTheme
import dev.snipme.highlights.model.SyntaxThemes
import dev.snipme.highlights.model.SyntaxThemes.useDark
import dev.snipme.kodeview.view.CodeEditText
import dev.snipme.kodeview.view.CodeTextView
import dev.snipme.kodeview.view.material3.CodeEditText

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
2 changes: 1 addition & 1 deletion desktopExample/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import dev.snipme.highlights.model.SyntaxLanguage
import dev.snipme.highlights.model.SyntaxTheme
import dev.snipme.highlights.model.SyntaxThemes
import dev.snipme.highlights.model.SyntaxThemes.useDark
import dev.snipme.kodeview.view.CodeEditText
import dev.snipme.kodeview.view.material3.CodeEditText
import dev.snipme.kodeview.view.CodeTextView

private val windowSize = 600.dp
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 -Dkotlin.daemon.jvm.options\=
#Kotlin
kotlin.code.style=official
kotlin.js.compiler=ir
kotlin.incremental.native=true

#Android
android.useAndroidX=true
Expand Down
14 changes: 9 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
[versions]
jvmTarget = "1.8"
gradlePlugin = "8.1.0"
kotlin = "1.9.10"
kotlin = "1.9.21"
ksp = "1.8.10-1.0.9"
kotlinCompilerExtensionVersion = "1.5.3"
kotlinAndroid = "1.9.10"
kotlinMultiplatform = "1.9.10"
compose = "1.5.2"
kotlinAndroid = "1.9.21"
kotlinMultiplatform = "1.9.21"
compose = "1.5.11"
androidLibrary = "8.1.1"
kodeview = "0.7.0"
kodeview = "0.8.0"
highlights = "0.7.1"
composeMaterial = "1.2.1"

[libraries]
kodeview = { group = "dev.snipme", name = "kodeview", version.ref = "kodeview" }
highlights = { group = "dev.snipme", name = "highlights", version.ref = "highlights" }
compose-material = { group = "androidx.wear.compose", name = "compose-material", version.ref = "composeMaterial" }

[plugins]
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
Expand Down
4 changes: 4 additions & 0 deletions iosExample/iosExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
837BACD82B4543E300BD8F35 /* CodeEditText.swift in Sources */ = {isa = PBXBuildFile; fileRef = 837BACD72B4543E300BD8F35 /* CodeEditText.swift */; };
83FF2D2E2A1A16AE001AEED3 /* iosExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83FF2D2D2A1A16AE001AEED3 /* iosExampleApp.swift */; };
83FF2D302A1A16AE001AEED3 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83FF2D2F2A1A16AE001AEED3 /* ContentView.swift */; };
83FF2D322A1A16AF001AEED3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 83FF2D312A1A16AF001AEED3 /* Assets.xcassets */; };
Expand Down Expand Up @@ -36,6 +37,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
837BACD72B4543E300BD8F35 /* CodeEditText.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodeEditText.swift; sourceTree = "<group>"; };
83FF2D2A2A1A16AE001AEED3 /* iosExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosExample.app; sourceTree = BUILT_PRODUCTS_DIR; };
83FF2D2D2A1A16AE001AEED3 /* iosExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iosExampleApp.swift; sourceTree = "<group>"; };
83FF2D2F2A1A16AE001AEED3 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -106,6 +108,7 @@
83FF2D342A1A16AF001AEED3 /* Preview Content */,
83FF2D582A1A16D4001AEED3 /* DropdownMenu.swift */,
83FF2D5A2A1A170E001AEED3 /* CodeTextView.swift */,
837BACD72B4543E300BD8F35 /* CodeEditText.swift */,
);
path = iosExample;
sourceTree = "<group>";
Expand Down Expand Up @@ -287,6 +290,7 @@
buildActionMask = 2147483647;
files = (
83FF2D5B2A1A170E001AEED3 /* CodeTextView.swift in Sources */,
837BACD82B4543E300BD8F35 /* CodeEditText.swift in Sources */,
83FF2D302A1A16AE001AEED3 /* ContentView.swift in Sources */,
83FF2D2E2A1A16AE001AEED3 /* iosExampleApp.swift in Sources */,
83FF2D592A1A16D4001AEED3 /* DropdownMenu.swift in Sources */,
Expand Down
Binary file not shown.
44 changes: 44 additions & 0 deletions iosExample/iosExample/CodeEditText.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// CodeEditText.swift
// iosExample
//
// Created by Tomasz Kądziołka on 03/01/2024.
//

import SwiftUI
import kodeview

struct CodeEditText: UIViewControllerRepresentable {
@Binding private var highlights: Highlights
private var onValueChange: (String) -> Void

init(
newHighlights: Binding<Highlights>,
onValueChange: @escaping (String) -> Void
) {
self._highlights = newHighlights
self.onValueChange = onValueChange
}

func makeUIViewController(context: Context) -> UIViewController {
return UIViewController()
}

func updateUIViewController(_ wrapper: UIViewController, context: Context) {
let kotlinController = CodeEditTextIos.shared.uiViewController(
highlights: highlights,
onValueChange: { value in
onValueChange(value.text)
}
)
// Cleanup
kotlinController.removeFromParent()
kotlinController.view.removeFromSuperview()
// Update view
wrapper.addChild(kotlinController)
wrapper.view.addSubview(kotlinController.view)
// Match with frame
kotlinController.view.frame = wrapper.view.frame
kotlinController.didMove(toParent: wrapper)
}
}
23 changes: 10 additions & 13 deletions iosExample/iosExample/CodeTextView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import SwiftUI
import kodeview

// Omit KMM library prefixing
typealias Highlights = HighlightsHighlights

struct CodeTextView: UIViewControllerRepresentable {
@Binding private var highlights: Highlights

Expand All @@ -23,15 +20,15 @@ struct CodeTextView: UIViewControllerRepresentable {
}

func updateUIViewController(_ wrapper: UIViewController, context: Context) {
let kotlinController = HighlightsViewKt.CodeTextViewUiViewController(highlights: highlights)
// Cleanup
kotlinController.removeFromParent()
kotlinController.view.removeFromSuperview()
// Update view
wrapper.addChild(kotlinController)
wrapper.view.addSubview(kotlinController.view)
// Match with frame
kotlinController.view.frame = wrapper.view.frame
kotlinController.didMove(toParent: wrapper)
let kotlinController = CodeTextViewIos.shared.uiViewController(highlights: highlights)
// Cleanup
kotlinController.removeFromParent()
kotlinController.view.removeFromSuperview()
// Update view
wrapper.addChild(kotlinController)
wrapper.view.addSubview(kotlinController.view)
// Match with frame
kotlinController.view.frame = wrapper.view.frame
kotlinController.didMove(toParent: wrapper)
}
}
12 changes: 9 additions & 3 deletions iosExample/iosExample/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@
import SwiftUI
import kodeview

typealias SyntaxLanguage = HighlightsSyntaxLanguage
typealias SyntaxTheme = HighlightsSyntaxTheme

struct ContentView: View {
@State var highlights = Highlights.companion.default()
private let themes = Highlights.companion.themes(darkMode: false)
Expand All @@ -36,6 +33,15 @@ struct ContentView: View {
.ignoresSafeArea(.keyboard)
.padding()
Divider()
CodeEditText(newHighlights: $highlights) { value in
$highlights.wrappedValue = highlights
.getBuilder()
.code(code: value)
.build()
}
.ignoresSafeArea(.keyboard)
.padding()
Divider()
DropdownMenu(
values: getThemeNames(themes: themes),
defaultSelection: getThemeNames(themes: themes)
Expand Down
29 changes: 8 additions & 21 deletions kodeview/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}

group = "dev.snipme"
version = "0.7.0"
version = "0.8.0"

android {
namespace = "dev.snipme.kodeview"
Expand All @@ -18,6 +18,9 @@ android {
minSdk = 21
}
}
dependencies {
implementation(libs.compose.material)
}

kotlin {
jvm()
Expand All @@ -40,12 +43,14 @@ kotlin {
iosSimulatorArm64()
).forEach {
it.binaries.framework {
// TODO Try to export Highlights with Kotlin 1.9.20
baseName = "kodeview"
isStatic = true
export(libs.highlights)
}
}

applyDefaultHierarchyTemplate()

sourceSets {
// Common
val commonMain by getting {
Expand All @@ -58,32 +63,14 @@ kotlin {
@OptIn(org.jetbrains.compose.ExperimentalComposeLibrary::class)
implementation(compose.components.resources)
// Share logic between submodules
api("dev.snipme:highlights:0.7.1")
api(libs.highlights)
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
// Android
val androidMain by getting {
dependencies {
implementation("androidx.activity:activity-compose:1.7.2")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("androidx.core:core-ktx:1.12.0")
}
}
// iOS
val iosX64Main by getting
val iosArm64Main by getting
val iosSimulatorArm64Main by getting
val iosMain by creating {
dependsOn(commonMain)
iosX64Main.dependsOn(this)
iosArm64Main.dependsOn(this)
iosSimulatorArm64Main.dependsOn(this)
}
}
}

Expand Down
Loading