Skip to content
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

Initial Jetpack work #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,19 @@ config :phoenix, :json_library, Jason

config :live_view_native,
plugins: [
LiveViewNative.SwiftUI
LiveViewNative.SwiftUI,
LiveViewNative.Jetpack
]

config :mime, :types, %{
"text/swiftui" => ["swiftui"],
"text/jetpack" => ["jetpack"],
"text/styles" => ["styles"]
}

config :phoenix_template, :format_encoders, swiftui: Phoenix.HTML.Engine
config :phoenix_template, :format_encoders,
swiftui: Phoenix.HTML.Engine,
jetpack: Phoenix.HTML.Engine

config :phoenix, :template_engines, neex: LiveViewNative.Engine

Expand Down
6 changes: 4 additions & 2 deletions lib/lax_native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ defmodule LaxNative do
quote do
use LiveViewNative.LiveView,
formats: [
:swiftui
:swiftui,
:jetpack
],
layouts: [
swiftui: {LaxWeb.Layouts.SwiftUI, :app}
swiftui: {LaxWeb.Layouts.SwiftUI, :app},
jetpack: {LaxWeb.Layouts.Jetpack, :app}
]

unquote(verified_routes())
Expand Down
19 changes: 19 additions & 0 deletions lib/lax_web/components/core_components.jetpack.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule LaxWeb.CoreComponents.Jetpack do
@moduledoc """
Provides core UI components built for Jetpack.

This file contains feature parity components to your applications's CoreComponent module.
The goal is to retain a common API for fast prototyping. Leveraging your existing knowledge
of the `LaxWeb.CoreComponents` functions you should expect identical functionality for similarly named
components between web and native. That means utilizing your existing `handle_event/3` functions to manage state
and stay focused on adding new templates for your native applications.

The default components use `LiveViewNative.Jetpack.UtilityStyles`, a generated styling syntax
that allows you to call nearly any modifier. Refer to the documentation in `LiveViewNative.Jetpack` for more information.

"""

use LiveViewNative.Component

import LiveViewNative.LiveForm.Component
end
5 changes: 5 additions & 0 deletions lib/lax_web/components/layouts.jetpack.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule LaxWeb.Layouts.Jetpack do
use LaxNative, [:layout, format: :jetpack]

embed_templates "layouts_jetpack/*"
end
1 change: 1 addition & 0 deletions lib/lax_web/components/layouts_jetpack/app.jetpack.neex
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= @inner_content %>
3 changes: 3 additions & 0 deletions lib/lax_web/components/layouts_jetpack/root.jetpack.neex
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<.csrf_token />
<Style url={~p"/assets/app.jetpack.styles"} />
<%= @inner_content %>
9 changes: 9 additions & 0 deletions lib/lax_web/live/chat_live.jetpack.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule LaxWeb.ChatLive.Jetpack do
use LaxNative, [:render_component, format: :swiftui]

def render(assigns, _interface) do
~LVN"""
<Text>Hello, Jetpack!</Text>
"""
end
end
5 changes: 3 additions & 2 deletions lib/lax_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ defmodule LaxWeb.Router do
import LaxWeb.UserAuth

pipeline :browser do
plug :accepts, ["html", "swiftui"]
plug :accepts, ["html", "swiftui", "jetpack"]
plug :fetch_session
plug :fetch_live_flash

plug :put_root_layout,
html: {LaxWeb.Layouts, :root},
swiftui: {LaxWeb.Layouts.SwiftUI, :root}
swiftui: {LaxWeb.Layouts.SwiftUI, :root},
jetpack: {LaxWeb.Layouts.Jetpack, :root}

plug :protect_from_forgery
plug :put_secure_browser_headers
Expand Down
21 changes: 21 additions & 0 deletions lib/lax_web/styles/app.jetpack.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule LaxWeb.Styles.App.Jetpack do
use LiveViewNative.Stylesheet, :jetpack

~SHEET"""
"color-red" do
color(.red)
end

# this is a comment and isn't included in the output

"button-" <> style do
# this is also a comment that isn't included in the output
buttonStyle(.<%= style %>)
end
"""

def class("color-" <> color_name) do
~RULES"""
"""
end
end
2 changes: 2 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ defmodule Lax.MixProject do
github: "liveview-native/live_view_native_stylesheet", branch: "main"},
{:live_view_native_swiftui,
github: "liveview-native/liveview-client-swiftui", branch: "main"},
{:live_view_native_jetpack,
github: "liveview-native/liveview-client-jetpack", branch: "main"},
{:live_view_native_live_form,
github: "liveview-native/liveview-native-live-form", branch: "main"},
{:pigeon, "~> 1.6.2"},
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"jose": {:hex, :jose, "1.11.10", "a903f5227417bd2a08c8a00a0cbcc458118be84480955e8d251297a425723f83", [:mix, :rebar3], [], "hexpm", "0d6cd36ff8ba174db29148fc112b5842186b68a90ce9fc2b3ec3afe76593e614"},
"kadabra": {:hex, :kadabra, "0.6.0", "8d8de886802f38d86d2c250eb9416e3208b5e4b78ce8409b40b4d57f21d21fc9", [:mix], [{:certifi, "~> 2.5", [hex: :certifi, repo: "hexpm", optional: false]}, {:hpack, "~> 0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}], "hexpm", "0cdaf72fc6205cba62da9e49ee6b24b7c50adb6d9f8b0e92b4b1847959371403"},
"live_view_native": {:git, "https://github.com/liveview-native/live_view_native.git", "65fc88252a21342116ed4ce4791e09c49d9d4c32", [branch: "main"]},
"live_view_native_jetpack": {:git, "https://github.com/liveview-native/liveview-client-jetpack.git", "6f5fc51c229c20375f32ac5f36af2a57b40a9f07", [branch: "main"]},
"live_view_native_live_form": {:git, "https://github.com/liveview-native/liveview-native-live-form.git", "84e9368996c8e869727548cfd6180b86fb5277f1", [branch: "main"]},
"live_view_native_stylesheet": {:git, "https://github.com/liveview-native/live_view_native_stylesheet.git", "10ca59477c049901b1b0de717ddb08d2eb30dadd", [branch: "main"]},
"live_view_native_swiftui": {:git, "https://github.com/liveview-native/liveview-client-swiftui.git", "9fe36d46499dfe3c9af29444a03e9f94a85742b4", [branch: "main"]},
Expand Down
15 changes: 15 additions & 0 deletions native/jetpack/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
local.properties
3 changes: 3 additions & 0 deletions native/jetpack/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions native/jetpack/.idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions native/jetpack/.idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions native/jetpack/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions native/jetpack/.idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions native/jetpack/.idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions native/jetpack/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions native/jetpack/.idea/runConfigurations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions native/jetpack/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions native/jetpack/app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
61 changes: 61 additions & 0 deletions native/jetpack/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
}

android {
namespace = "so.lax.Lax"
compileSdk = 35

defaultConfig {
applicationId = "so.lax.Lax"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
buildFeatures {
compose = true
}
}

dependencies {
implementation("com.github.liveview-native:liveview-client-jetpack:main-SNAPSHOT") {
isChanging = true
}
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(libs.androidx.activity.compose)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.ui)
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}
21 changes: 21 additions & 0 deletions native/jetpack/app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package so.lax.Lax

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("so.lax.Lax", appContext.packageName)
}
}
29 changes: 29 additions & 0 deletions native/jetpack/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Lax"
android:networkSecurityConfig="@xml/network_config"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true"
android:label="@string/app_name"
android:theme="@style/Theme.Lax">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Loading