vaderjs-native 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.MD +99 -0
  3. package/app-template/.idea/.name +1 -0
  4. package/app-template/.idea/AndroidProjectSystem.xml +6 -0
  5. package/app-template/.idea/codeStyles/Project.xml +123 -0
  6. package/app-template/.idea/codeStyles/codeStyleConfig.xml +5 -0
  7. package/app-template/.idea/compiler.xml +6 -0
  8. package/app-template/.idea/deploymentTargetSelector.xml +10 -0
  9. package/app-template/.idea/gradle.xml +19 -0
  10. package/app-template/.idea/inspectionProfiles/Project_Default.xml +61 -0
  11. package/app-template/.idea/migrations.xml +10 -0
  12. package/app-template/.idea/misc.xml +9 -0
  13. package/app-template/.idea/runConfigurations.xml +17 -0
  14. package/app-template/app/build.gradle.kts +54 -0
  15. package/app-template/app/proguard-rules.pro +21 -0
  16. package/app-template/app/src/main/AndroidManifest.xml +31 -0
  17. package/app-template/app/src/main/java/com/example/myapplication/MainActivity.kt +74 -0
  18. package/app-template/app/src/main/java/com/example/myapplication/ui/theme/Color.kt +11 -0
  19. package/app-template/app/src/main/java/com/example/myapplication/ui/theme/Theme.kt +34 -0
  20. package/app-template/app/src/main/java/com/example/myapplication/ui/theme/Type.kt +36 -0
  21. package/app-template/app/src/main/res/mipmap-hdpi/ic_launcher.webp +0 -0
  22. package/app-template/app/src/main/res/mipmap-mdpi/ic_launcher.webp +0 -0
  23. package/app-template/app/src/main/res/mipmap-xhdpi/ic_launcher.webp +0 -0
  24. package/app-template/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp +0 -0
  25. package/app-template/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp +0 -0
  26. package/app-template/app/src/main/res/values/strings.xml +3 -0
  27. package/app-template/app/src/main/res/values/themes.xml +4 -0
  28. package/app-template/build.gradle.kts +5 -0
  29. package/app-template/gradle/libs.versions.toml +30 -0
  30. package/app-template/gradle/wrapper/gradle-wrapper.jar +0 -0
  31. package/app-template/gradle/wrapper/gradle-wrapper.properties +9 -0
  32. package/app-template/gradle.properties +23 -0
  33. package/app-template/gradlew +251 -0
  34. package/app-template/gradlew.bat +94 -0
  35. package/app-template/settings.gradle.kts +23 -0
  36. package/cli.ts +232 -0
  37. package/config/index.ts +14 -0
  38. package/index.ts +1083 -0
  39. package/jsconfig.json +7 -0
  40. package/logo.png +0 -0
  41. package/main.js +643 -0
  42. package/package.json +20 -0
  43. package/plugins/index.ts +63 -0
  44. package/plugins/tailwind.ts +53 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Pascal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.MD ADDED
@@ -0,0 +1,99 @@
1
+ <p align="center">
2
+ <a href="https://vader-js.pages.dev">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="/icon.jpeg">
5
+ <img src="https://github.com/Postr-Inc/Vader.js/blob/main/logo.png" height="128">
6
+ </picture>
7
+ <h1 align="center">Vader.js</h1>
8
+ </a>
9
+ </p>
10
+
11
+ # Vader.js
12
+ A modern, reactive framework for building ultra-fast android applications — built on simplicity and speed.
13
+
14
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Postr-Inc/Vader.js/blob/main/LICENSE) [![npm version](https://img.shields.io/npm/v/vaderjs.svg?style=flat)](https://www.npmjs.com/package/vaderjs)
15
+
16
+ ---
17
+
18
+ ## 🚀 Quick Example
19
+
20
+ ```tsx
21
+ import * as Vader from "vader-native"
22
+
23
+ export default function() {
24
+ const [count, setCount] = useState(0)
25
+ return (
26
+ <div>
27
+ <Switch>
28
+ <Match when={count > 10}>
29
+ <h1>Count is greater than 10</h1>
30
+ </Match>
31
+ <Match when={count <= 10}>
32
+ <h1>Count is less than or equal to 10</h1>
33
+ </Match>
34
+ </Switch>
35
+ </div>
36
+ )
37
+ }
38
+ ```
39
+
40
+ ---
41
+
42
+ ## 📦 Installation
43
+
44
+ ```bash
45
+ bun install vaderjs@latest
46
+ ```
47
+
48
+ ## ⚙️ Project Structure
49
+
50
+ Vader.js supports file-based routing out of the box. Just create a `pages` folder like in Next.js:
51
+
52
+ > ⚠️ Note: This routing system is designed for **production servers** only. It will not work with Cloudflare Pages, GitHub Pages, or Vercel.
53
+
54
+ You can nest up to 4 levels deep.
55
+
56
+ ```
57
+ /pages/index.jsx -> /
58
+ /pages/home/[page].jsx -> /home/:page
59
+ /pages/path/index.jsx -> /path/
60
+ /pages/test/[[...catchall]]/index.jsx -> /test/*
61
+ /pages/route/[param1]/[param2].jsx -> /route/:param1/:param2
62
+ ```
63
+
64
+ ---
65
+
66
+ ## 🗂 Keyword Folders
67
+
68
+ Certain folders are special and automatically picked up by the bundler:
69
+
70
+ | Folder | Purpose |
71
+ | --------- | ----------------------------------- |
72
+ | `app/` | Contains all route `.jsx` files |
73
+ | `src/` | Your components, utilities, etc. |
74
+ | `public/` | Static files like CSS, JSON, images |
75
+
76
+ ---
77
+
78
+ ## 🛠 Define Config
79
+
80
+ Create a `config.ts` file at the root of your project:
81
+
82
+ ```ts
83
+ import defineConfig from "vaderjs/config";
84
+
85
+ export default defineConfig({
86
+ port: 3000,
87
+ host: "localhost",
88
+ hot_reload: true,
89
+ });
90
+ ```
91
+
92
+
93
+ ## 🤔 Why Vader.js?
94
+
95
+ * Minimal reactivity model with zero VDOM
96
+ * File-based routing system built into Bun
97
+ * Tiny runtime, blazing fast updates
98
+ * Familiar API inspired by React, but simpler
99
+ * Perfect for Bun-first, fullstack apps
@@ -0,0 +1 @@
1
+ My Application
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="AndroidProjectSystem">
4
+ <option name="providerId" value="com.android.tools.idea.GradleProjectSystem" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,123 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <code_scheme name="Project" version="173">
3
+ <JetCodeStyleSettings>
4
+ <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
5
+ </JetCodeStyleSettings>
6
+ <codeStyleSettings language="XML">
7
+ <option name="FORCE_REARRANGE_MODE" value="1" />
8
+ <indentOptions>
9
+ <option name="CONTINUATION_INDENT_SIZE" value="4" />
10
+ </indentOptions>
11
+ <arrangement>
12
+ <rules>
13
+ <section>
14
+ <rule>
15
+ <match>
16
+ <AND>
17
+ <NAME>xmlns:android</NAME>
18
+ <XML_ATTRIBUTE />
19
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
20
+ </AND>
21
+ </match>
22
+ </rule>
23
+ </section>
24
+ <section>
25
+ <rule>
26
+ <match>
27
+ <AND>
28
+ <NAME>xmlns:.*</NAME>
29
+ <XML_ATTRIBUTE />
30
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
31
+ </AND>
32
+ </match>
33
+ <order>BY_NAME</order>
34
+ </rule>
35
+ </section>
36
+ <section>
37
+ <rule>
38
+ <match>
39
+ <AND>
40
+ <NAME>.*:id</NAME>
41
+ <XML_ATTRIBUTE />
42
+ <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
43
+ </AND>
44
+ </match>
45
+ </rule>
46
+ </section>
47
+ <section>
48
+ <rule>
49
+ <match>
50
+ <AND>
51
+ <NAME>.*:name</NAME>
52
+ <XML_ATTRIBUTE />
53
+ <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
54
+ </AND>
55
+ </match>
56
+ </rule>
57
+ </section>
58
+ <section>
59
+ <rule>
60
+ <match>
61
+ <AND>
62
+ <NAME>name</NAME>
63
+ <XML_ATTRIBUTE />
64
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
65
+ </AND>
66
+ </match>
67
+ </rule>
68
+ </section>
69
+ <section>
70
+ <rule>
71
+ <match>
72
+ <AND>
73
+ <NAME>style</NAME>
74
+ <XML_ATTRIBUTE />
75
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
76
+ </AND>
77
+ </match>
78
+ </rule>
79
+ </section>
80
+ <section>
81
+ <rule>
82
+ <match>
83
+ <AND>
84
+ <NAME>.*</NAME>
85
+ <XML_ATTRIBUTE />
86
+ <XML_NAMESPACE>^$</XML_NAMESPACE>
87
+ </AND>
88
+ </match>
89
+ <order>BY_NAME</order>
90
+ </rule>
91
+ </section>
92
+ <section>
93
+ <rule>
94
+ <match>
95
+ <AND>
96
+ <NAME>.*</NAME>
97
+ <XML_ATTRIBUTE />
98
+ <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
99
+ </AND>
100
+ </match>
101
+ <order>ANDROID_ATTRIBUTE_ORDER</order>
102
+ </rule>
103
+ </section>
104
+ <section>
105
+ <rule>
106
+ <match>
107
+ <AND>
108
+ <NAME>.*</NAME>
109
+ <XML_ATTRIBUTE />
110
+ <XML_NAMESPACE>.*</XML_NAMESPACE>
111
+ </AND>
112
+ </match>
113
+ <order>BY_NAME</order>
114
+ </rule>
115
+ </section>
116
+ </rules>
117
+ </arrangement>
118
+ </codeStyleSettings>
119
+ <codeStyleSettings language="kotlin">
120
+ <option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />
121
+ </codeStyleSettings>
122
+ </code_scheme>
123
+ </component>
@@ -0,0 +1,5 @@
1
+ <component name="ProjectCodeStyleConfiguration">
2
+ <state>
3
+ <option name="USE_PER_PROJECT_SETTINGS" value="true" />
4
+ </state>
5
+ </component>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="CompilerConfiguration">
4
+ <bytecodeTargetLevel target="21" />
5
+ </component>
6
+ </project>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="deploymentTargetSelector">
4
+ <selectionStates>
5
+ <SelectionState runConfigName="app">
6
+ <option name="selectionMode" value="DROPDOWN" />
7
+ </SelectionState>
8
+ </selectionStates>
9
+ </component>
10
+ </project>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="GradleMigrationSettings" migrationVersion="1" />
4
+ <component name="GradleSettings">
5
+ <option name="linkedExternalProjectsSettings">
6
+ <GradleProjectSettings>
7
+ <option name="testRunner" value="CHOOSE_PER_TEST" />
8
+ <option name="externalProjectPath" value="$PROJECT_DIR$" />
9
+ <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
10
+ <option name="modules">
11
+ <set>
12
+ <option value="$PROJECT_DIR$" />
13
+ <option value="$PROJECT_DIR$/app" />
14
+ </set>
15
+ </option>
16
+ </GradleProjectSettings>
17
+ </option>
18
+ </component>
19
+ </project>
@@ -0,0 +1,61 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="ComposePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
5
+ <option name="composableFile" value="true" />
6
+ <option name="previewFile" value="true" />
7
+ </inspection_tool>
8
+ <inspection_tool class="ComposePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
9
+ <option name="composableFile" value="true" />
10
+ <option name="previewFile" value="true" />
11
+ </inspection_tool>
12
+ <inspection_tool class="ComposePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
13
+ <option name="composableFile" value="true" />
14
+ <option name="previewFile" value="true" />
15
+ </inspection_tool>
16
+ <inspection_tool class="ComposePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
17
+ <option name="composableFile" value="true" />
18
+ <option name="previewFile" value="true" />
19
+ </inspection_tool>
20
+ <inspection_tool class="GlancePreviewDimensionRespectsLimit" enabled="true" level="WARNING" enabled_by_default="true">
21
+ <option name="composableFile" value="true" />
22
+ </inspection_tool>
23
+ <inspection_tool class="GlancePreviewMustBeTopLevelFunction" enabled="true" level="ERROR" enabled_by_default="true">
24
+ <option name="composableFile" value="true" />
25
+ </inspection_tool>
26
+ <inspection_tool class="GlancePreviewNeedsComposableAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
27
+ <option name="composableFile" value="true" />
28
+ </inspection_tool>
29
+ <inspection_tool class="GlancePreviewNotSupportedInUnitTestFiles" enabled="true" level="ERROR" enabled_by_default="true">
30
+ <option name="composableFile" value="true" />
31
+ </inspection_tool>
32
+ <inspection_tool class="PreviewAnnotationInFunctionWithParameters" enabled="true" level="ERROR" enabled_by_default="true">
33
+ <option name="composableFile" value="true" />
34
+ <option name="previewFile" value="true" />
35
+ </inspection_tool>
36
+ <inspection_tool class="PreviewApiLevelMustBeValid" enabled="true" level="ERROR" enabled_by_default="true">
37
+ <option name="composableFile" value="true" />
38
+ <option name="previewFile" value="true" />
39
+ </inspection_tool>
40
+ <inspection_tool class="PreviewDeviceShouldUseNewSpec" enabled="true" level="WEAK WARNING" enabled_by_default="true">
41
+ <option name="composableFile" value="true" />
42
+ <option name="previewFile" value="true" />
43
+ </inspection_tool>
44
+ <inspection_tool class="PreviewFontScaleMustBeGreaterThanZero" enabled="true" level="ERROR" enabled_by_default="true">
45
+ <option name="composableFile" value="true" />
46
+ <option name="previewFile" value="true" />
47
+ </inspection_tool>
48
+ <inspection_tool class="PreviewMultipleParameterProviders" enabled="true" level="ERROR" enabled_by_default="true">
49
+ <option name="composableFile" value="true" />
50
+ <option name="previewFile" value="true" />
51
+ </inspection_tool>
52
+ <inspection_tool class="PreviewParameterProviderOnFirstParameter" enabled="true" level="ERROR" enabled_by_default="true">
53
+ <option name="composableFile" value="true" />
54
+ <option name="previewFile" value="true" />
55
+ </inspection_tool>
56
+ <inspection_tool class="PreviewPickerAnnotation" enabled="true" level="ERROR" enabled_by_default="true">
57
+ <option name="composableFile" value="true" />
58
+ <option name="previewFile" value="true" />
59
+ </inspection_tool>
60
+ </profile>
61
+ </component>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="ProjectMigrations">
4
+ <option name="MigrateToGradleLocalJavaHome">
5
+ <set>
6
+ <option value="$PROJECT_DIR$" />
7
+ </set>
8
+ </option>
9
+ </component>
10
+ </project>
@@ -0,0 +1,9 @@
1
+ <project version="4">
2
+ <component name="ExternalStorageConfigurationManager" enabled="true" />
3
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
4
+ <output url="file://$PROJECT_DIR$/build/classes" />
5
+ </component>
6
+ <component name="ProjectType">
7
+ <option name="id" value="Android" />
8
+ </component>
9
+ </project>
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <project version="4">
3
+ <component name="RunConfigurationProducerService">
4
+ <option name="ignoredProducers">
5
+ <set>
6
+ <option value="com.intellij.execution.junit.AbstractAllInDirectoryConfigurationProducer" />
7
+ <option value="com.intellij.execution.junit.AllInPackageConfigurationProducer" />
8
+ <option value="com.intellij.execution.junit.PatternConfigurationProducer" />
9
+ <option value="com.intellij.execution.junit.TestInClassConfigurationProducer" />
10
+ <option value="com.intellij.execution.junit.UniqueIdConfigurationProducer" />
11
+ <option value="com.intellij.execution.junit.testDiscovery.JUnitTestDiscoveryConfigurationProducer" />
12
+ <option value="org.jetbrains.kotlin.idea.junit.KotlinJUnitRunConfigurationProducer" />
13
+ <option value="org.jetbrains.kotlin.idea.junit.KotlinPatternConfigurationProducer" />
14
+ </set>
15
+ </option>
16
+ </component>
17
+ </project>
@@ -0,0 +1,54 @@
1
+ plugins {
2
+ alias(libs.plugins.android.application)
3
+ alias(libs.plugins.kotlin.compose)
4
+ }
5
+
6
+ android {
7
+ namespace = "com.example.myapplication"
8
+ compileSdk {
9
+ version = release(36)
10
+ }
11
+
12
+ defaultConfig {
13
+ applicationId = "com.example.myapplication"
14
+ minSdk = 21
15
+ targetSdk = 36
16
+ versionCode = 1
17
+ versionName = "1.0"
18
+
19
+ }
20
+
21
+ buildTypes {
22
+ release {
23
+ isMinifyEnabled = false
24
+ proguardFiles(
25
+ getDefaultProguardFile("proguard-android-optimize.txt"),
26
+ "proguard-rules.pro"
27
+ )
28
+ }
29
+ }
30
+ compileOptions {
31
+ sourceCompatibility = JavaVersion.VERSION_11
32
+ targetCompatibility = JavaVersion.VERSION_11
33
+ }
34
+ buildFeatures {
35
+ compose = true
36
+ }
37
+ }
38
+
39
+ dependencies {
40
+ implementation(libs.androidx.core.ktx)
41
+ implementation(libs.androidx.appcompat)
42
+ implementation(platform(libs.androidx.compose.bom))
43
+ implementation(libs.androidx.compose.ui)
44
+ implementation(libs.androidx.compose.ui.graphics)
45
+ implementation(libs.androidx.compose.ui.tooling.preview)
46
+ implementation(libs.androidx.tv.foundation)
47
+ implementation(libs.androidx.tv.material)
48
+ implementation(libs.androidx.lifecycle.runtime.ktx)
49
+ implementation(libs.androidx.activity.compose)
50
+ androidTestImplementation(platform(libs.androidx.compose.bom))
51
+ androidTestImplementation(libs.androidx.compose.ui.test.junit4)
52
+ debugImplementation(libs.androidx.compose.ui.tooling)
53
+ debugImplementation(libs.androidx.compose.ui.test.manifest)
54
+ }
@@ -0,0 +1,21 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile
@@ -0,0 +1,31 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
3
+ xmlns:tools="http://schemas.android.com/tools">
4
+
5
+ <uses-feature
6
+ android:name="android.hardware.touchscreen"
7
+ android:required="false" />
8
+ <uses-feature
9
+ android:name="android.software.leanback"
10
+ android:required="false" />
11
+
12
+ <application
13
+ android:allowBackup="true"
14
+ android:banner="@mipmap/ic_launcher"
15
+ android:icon="@mipmap/ic_launcher"
16
+ android:label="@string/app_name"
17
+ android:supportsRtl="true"
18
+ android:theme="@style/Theme.MyApplication">
19
+ <activity
20
+ android:name=".MainActivity"
21
+ android:exported="true">
22
+ <intent-filter>
23
+ <action android:name="android.intent.action.MAIN" />
24
+
25
+ <category android:name="android.intent.category.LAUNCHER" />
26
+ <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
27
+ </intent-filter>
28
+ </activity>
29
+ </application>
30
+
31
+ </manifest>
@@ -0,0 +1,74 @@
1
+ package com.example.myapplication
2
+
3
+ import android.content.Context
4
+ import android.os.Bundle
5
+ import android.webkit.JavascriptInterface
6
+ import android.webkit.WebView
7
+ import android.webkit.WebViewClient
8
+ import android.widget.Toast
9
+ import androidx.activity.ComponentActivity
10
+
11
+ class MainActivity : ComponentActivity() {
12
+ lateinit var webView: WebView
13
+
14
+ override fun onCreate(savedInstanceState: Bundle?) {
15
+ super.onCreate(savedInstanceState)
16
+
17
+ // Create WebView programmatically
18
+ webView = WebView(this)
19
+ setContentView(webView)
20
+
21
+ // Enable JS
22
+ webView.settings.javaScriptEnabled = true
23
+
24
+ // Make links stay in the WebView
25
+ webView.webViewClient = WebViewClient()
26
+
27
+ // Add JS -> Android bridge
28
+ webView.addJavascriptInterface(
29
+ AndroidBridge(this, webView),
30
+ "Android"
31
+ )
32
+
33
+ // Load VaderJS dist index.html
34
+ webView.loadUrl("file:///android_asset/myapp/index.html")
35
+ WebView.setWebContentsDebuggingEnabled(true)
36
+
37
+ }
38
+ }
39
+
40
+ // JS -> Android bridge
41
+ class AndroidBridge(
42
+ private val context: Context,
43
+ private val webView: WebView
44
+ ) {
45
+
46
+ @JavascriptInterface
47
+ fun showToast(message: String) {
48
+ Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
49
+ }
50
+
51
+ @JavascriptInterface
52
+ fun getDeviceName(): String {
53
+ return android.os.Build.MODEL
54
+ }
55
+
56
+
57
+
58
+ @JavascriptInterface
59
+ fun navigate(path: String?) {
60
+ val cleanPath = when {
61
+ path.isNullOrBlank() || path == "/" -> ""
62
+ path.startsWith("/") -> path
63
+ else -> "/$path"
64
+ }
65
+
66
+ webView.post {
67
+ webView.loadUrl(
68
+ "file:///android_asset/myapp$cleanPath/index.html"
69
+ )
70
+ }
71
+ }
72
+
73
+ }
74
+
@@ -0,0 +1,11 @@
1
+ package com.example.myapplication.ui.theme
2
+
3
+ import androidx.compose.ui.graphics.Color
4
+
5
+ val Purple80 = Color(0xFFD0BCFF)
6
+ val PurpleGrey80 = Color(0xFFCCC2DC)
7
+ val Pink80 = Color(0xFFEFB8C8)
8
+
9
+ val Purple40 = Color(0xFF6650a4)
10
+ val PurpleGrey40 = Color(0xFF625b71)
11
+ val Pink40 = Color(0xFF7D5260)
@@ -0,0 +1,34 @@
1
+ package com.example.myapplication.ui.theme
2
+
3
+ import androidx.compose.foundation.isSystemInDarkTheme
4
+ import androidx.compose.runtime.Composable
5
+ import androidx.tv.material3.ExperimentalTvMaterial3Api
6
+ import androidx.tv.material3.MaterialTheme
7
+ import androidx.tv.material3.darkColorScheme
8
+ import androidx.tv.material3.lightColorScheme
9
+
10
+ @OptIn(ExperimentalTvMaterial3Api::class)
11
+ @Composable
12
+ fun MyApplicationTheme(
13
+ isInDarkTheme: Boolean = isSystemInDarkTheme(),
14
+ content: @Composable () -> Unit,
15
+ ) {
16
+ val colorScheme = if (isInDarkTheme) {
17
+ darkColorScheme(
18
+ primary = Purple80,
19
+ secondary = PurpleGrey80,
20
+ tertiary = Pink80
21
+ )
22
+ } else {
23
+ lightColorScheme(
24
+ primary = Purple40,
25
+ secondary = PurpleGrey40,
26
+ tertiary = Pink40
27
+ )
28
+ }
29
+ MaterialTheme(
30
+ colorScheme = colorScheme,
31
+ typography = Typography,
32
+ content = content
33
+ )
34
+ }