-
Notifications
You must be signed in to change notification settings - Fork 0
feat(example): Update sample app #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3258d35
188abed
7e539a1
33a5e16
b835f48
d4858e3
c82113f
e36eee6
3613de5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,64 +15,96 @@ | |
| */ | ||
| package io.github.komodgn.example | ||
|
|
||
| import androidx.compose.foundation.background | ||
| import androidx.compose.foundation.layout.Arrangement | ||
| import androidx.compose.foundation.layout.BoxWithConstraints | ||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.Row | ||
| import androidx.compose.foundation.layout.WindowInsets | ||
| import androidx.compose.foundation.layout.displayCutoutPadding | ||
| import androidx.compose.foundation.layout.fillMaxSize | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.imePadding | ||
| import androidx.compose.foundation.layout.navigationBarsPadding | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.foundation.layout.statusBarsPadding | ||
| import androidx.compose.foundation.rememberScrollState | ||
| import androidx.compose.foundation.verticalScroll | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Scaffold | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.remember | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.unit.dp | ||
| import io.github.komodgn.AppConfig | ||
| import io.github.komodgn.codeview.compose.CodeView | ||
| import io.github.komodgn.codeview.core.CodeLanguage | ||
| import io.github.komodgn.example.component.CodeViewSection | ||
| import io.github.komodgn.example.component.EditorSection | ||
| import io.github.komodgn.example.theme.CodeViewTheme | ||
|
|
||
| @Composable | ||
| fun App() { | ||
| var userInput by remember { mutableStateOf(getInitialCode(AppConfig.LIBRARY_VERSION)) } | ||
| val scrollState = rememberScrollState() | ||
|
|
||
| val demoCode = """ | ||
| package io.github.komodgn.example | ||
|
|
||
| /** | ||
| * CodeView enables seamless syntax highlighting within KMP projects. | ||
| * It efficiently handles multi-line documentation and complex annotations. | ||
| */ | ||
| @Composable | ||
| fun CodeDisplay(version: String) { | ||
| // You can integrate dynamic string interpolation effortlessly | ||
| val greeting = "Hello, CodeView ${AppConfig.LIBRARY_VERSION} version" | ||
|
|
||
| /* | ||
| Block comment support: | ||
| Developers can verify the accuracy of color rendering | ||
| for improved code readability. | ||
| */ | ||
| CodeView( | ||
| code = greeting, | ||
| language = CodeLanguage.KOTLIN, | ||
| ) | ||
| } | ||
| """.trimIndent() | ||
|
|
||
| MaterialTheme { | ||
| CodeViewTheme { | ||
| Scaffold( | ||
| modifier = Modifier.fillMaxSize(), | ||
| modifier = Modifier | ||
| .fillMaxSize(), | ||
| contentWindowInsets = WindowInsets(0, 0, 0, 0), | ||
| ) { innerPadding -> | ||
| Column( | ||
| BoxWithConstraints( | ||
| modifier = Modifier | ||
| .padding(innerPadding) | ||
| .padding(16.dp) | ||
| .fillMaxSize() | ||
| .verticalScroll(scrollState), | ||
| .background(Color.White) | ||
| .statusBarsPadding() | ||
| .displayCutoutPadding() | ||
| .navigationBarsPadding() | ||
| .imePadding(), | ||
| ) { | ||
| CodeView( | ||
| code = demoCode, | ||
| language = CodeLanguage.KOTLIN, | ||
| ) | ||
| val isCompact = maxWidth < 600.dp | ||
|
|
||
| Column( | ||
| modifier = Modifier | ||
| .fillMaxWidth() | ||
| .verticalScroll(scrollState) | ||
| .padding(horizontal = 16.dp, vertical = 8.dp), | ||
| verticalArrangement = Arrangement.Center, | ||
| ) { | ||
| if (isCompact) { | ||
| CodeViewSection(userInput, modifier = Modifier.fillMaxWidth()) | ||
| EditorSection(userInput, onValueChange = { userInput = it }, modifier = Modifier.fillMaxWidth()) | ||
| } else { | ||
| Row(modifier = Modifier.fillMaxWidth().padding(16.dp, 0.dp, 16.dp, 0.dp)) { | ||
| EditorSection(userInput, onValueChange = { userInput = it }, modifier = Modifier.weight(1f)) | ||
| CodeViewSection(userInput, modifier = Modifier.weight(1f)) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun getInitialCode(version: String) = """ | ||
| package io.github.komodgn.example | ||
|
|
||
| /** | ||
| * Welcome to Compose CodeView v$version Demo! | ||
| * | ||
| * This library provides syntax highlighting for Compose Multiplatform. | ||
| * Feel free to edit the code on the left to see real-time updates. | ||
| */ | ||
| @Composable | ||
| fun CodeDisplay() { | ||
| val greeting = println("Hello, CodeView!") | ||
|
|
||
| CodeView( | ||
| code = greeting, | ||
| language = CodeLanguage.KOTLIN, | ||
| ) | ||
| } | ||
| """.trimIndent() | ||
|
Comment on lines
+92
to
+110
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Demo snippet in
🐛 Proposed fix- val greeting = println("Hello, CodeView!")
+ val greeting = "Hello, CodeView!"
CodeView(
code = greeting,🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * Copyright (C) 2026 komodgn | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.komodgn.example.component | ||
|
|
||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.unit.dp | ||
| import io.github.komodgn.codeview.compose.CodeView | ||
| import io.github.komodgn.codeview.core.CodeLanguage | ||
| import io.github.komodgn.example.theme.LocalAppFontFamily | ||
|
|
||
| @Composable | ||
| fun CodeViewSection(code: String, modifier: Modifier) { | ||
| Column(modifier = modifier.padding(8.dp)) { | ||
| Text("Preview", modifier = Modifier.padding(4.dp)) | ||
| CodeView( | ||
| code = code, | ||
| language = CodeLanguage.KOTLIN, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| fontFamily = LocalAppFontFamily.current, | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Copyright (C) 2026 komodgn | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.komodgn.example.component | ||
|
|
||
| import androidx.compose.foundation.layout.Column | ||
| import androidx.compose.foundation.layout.fillMaxWidth | ||
| import androidx.compose.foundation.layout.padding | ||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Text | ||
| import androidx.compose.material3.TextField | ||
| import androidx.compose.material3.TextFieldDefaults | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.ui.Modifier | ||
| import androidx.compose.ui.graphics.Color | ||
| import androidx.compose.ui.unit.dp | ||
| import io.github.komodgn.example.theme.LocalAppFontFamily | ||
|
|
||
| @Composable | ||
| fun EditorSection(code: String, onValueChange: (String) -> Unit, modifier: Modifier) { | ||
| Column(modifier = modifier.padding(8.dp)) { | ||
| Text("Edit Code", modifier = Modifier.padding(4.dp)) | ||
| TextField( | ||
| value = code, | ||
| onValueChange = onValueChange, | ||
| modifier = Modifier.fillMaxWidth(), | ||
| textStyle = MaterialTheme.typography.bodyMedium.copy( | ||
| fontFamily = LocalAppFontFamily.current, | ||
| ), | ||
| colors = TextFieldDefaults.colors( | ||
| focusedContainerColor = Color.Blue.copy(0.3f), | ||
| ), | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Copyright (C) 2026 komodgn | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.komodgn.example.theme | ||
|
|
||
| import androidx.compose.material3.MaterialTheme | ||
| import androidx.compose.material3.Typography | ||
| import androidx.compose.runtime.Composable | ||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.ui.text.TextStyle | ||
| import androidx.compose.ui.text.font.FontFamily | ||
| import compose_codeview.example.generated.resources.Res | ||
| import compose_codeview.example.generated.resources.* | ||
| import org.jetbrains.compose.resources.Font | ||
|
|
||
| @Composable | ||
| fun CodeViewTheme(content: @Composable () -> Unit) { | ||
| val codeFont = FontFamily( | ||
| Font(Res.font.NotoSansKR_Regular), | ||
| Font(Res.font.NotoColorEmoji), | ||
| ) | ||
|
|
||
| val typography = Typography( | ||
| bodyMedium = TextStyle( | ||
| fontFamily = codeFont, | ||
| ), | ||
| labelLarge = TextStyle( | ||
| fontFamily = codeFont, | ||
| ), | ||
| ) | ||
|
|
||
| CompositionLocalProvider(LocalAppFontFamily provides codeFont) { | ||
| MaterialTheme( | ||
| typography = typography, | ||
| content = content, | ||
| ) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /* | ||
| * Copyright (C) 2026 komodgn | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.komodgn.example.theme | ||
|
|
||
| import androidx.compose.runtime.staticCompositionLocalOf | ||
| import androidx.compose.ui.text.font.FontFamily | ||
|
|
||
| val LocalAppFontFamily = staticCompositionLocalOf<FontFamily> { | ||
| FontFamily.Default | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| /* | ||
| * Copyright (C) 2026 komodgn | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package io.github.komodgn.example | ||
|
|
||
| actual fun platform() = "Web with JS" |
Uh oh!
There was an error while loading. Please reload this page.