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

Bump liveview native library versions to 0.4.0 #17

Open
wants to merge 9 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ cookbook-*.tar
# In case you use Node.js/npm, you want to ignore these.
npm-debug.log
/assets/node_modules/

.DS_Store
3 changes: 2 additions & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ config :live_view_native_stylesheet,
content: [
swiftui: [
"lib/**/swiftui/*",
"lib/**/*swiftui*"
"lib/**/*swiftui*",
{:live_view_native_swiftui, "lib/**/swiftui/*"}
]
],
output: "priv/static/assets"
Expand Down
6 changes: 3 additions & 3 deletions lib/cookbook_native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ defmodule CookbookNative do
quote do
use LiveViewNative.Component, unquote(opts)

import LiveViewNative.Component, only: [csrf_token: 1]
import LiveViewNative.Component, only: [csrf_token: 2]

unquote(helpers(opts[:format]))
end
Expand All @@ -123,7 +123,7 @@ defmodule CookbookNative do
gettext_quoted = quote do
import CookbookWeb.Gettext
end

plugin = LiveViewNative.fetch_plugin!(format)

plugin_component_quoted = try do
Expand Down Expand Up @@ -159,7 +159,7 @@ defmodule CookbookNative do
core_component_quoted,
verified_routes()
]

end

@doc """
Expand Down
38 changes: 19 additions & 19 deletions lib/cookbook_web/components/core_components.swiftui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do

slot :inner_block

def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns, _interface) do
assigns
|> assign(field: nil, id: assigns.id || field.id)
|> assign(:errors, Enum.map(field.errors, &translate_error(&1)))
Expand Down Expand Up @@ -229,7 +229,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
@doc type: :component
slot :inner_block, required: true

def error(assigns) do
def error(assigns, _interface) do
~LVN"""
<Group style="font(.caption); foregroundStyle(.red)">
<%= render_slot(@inner_block) %>
Expand All @@ -248,7 +248,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
slot :subtitle
slot :actions

def header(assigns) do
def header(assigns, _interface) do
~LVN"""
<VStack style={[
"navigationTitle(:title)",
Expand Down Expand Up @@ -290,7 +290,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
attr :on_cancel, :string, default: nil
slot :inner_block, required: true

def modal(assigns) do
def modal(assigns, _interface) do
~LVN"""
<VStack
id={@id}
Expand Down Expand Up @@ -322,7 +322,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do

slot :inner_block, doc: "the optional inner block that renders the flash message"

def flash(assigns) do
def flash(assigns, _interface) do
assigns = assign_new(assigns, :id, fn -> "flash-#{assigns.kind}" end)

~LVN"""
Expand Down Expand Up @@ -354,7 +354,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
attr :flash, :map, required: true, doc: "the map of flash messages"
attr :id, :string, default: "flash-group", doc: "the optional id of flash container"

def flash_group(assigns) do
def flash_group(assigns, _interface) do
~LVN"""
<Group id={@id}>
<.flash kind={:info} title={"Success!"} flash={@flash} />
Expand Down Expand Up @@ -390,7 +390,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
slot :inner_block, required: true
slot :actions, doc: "the slot for form actions, such as a submit button"

def simple_form(assigns) do
def simple_form(assigns, _interface) do
~LVN"""
<.form :let={f} for={@for} as={@as} {@rest}>
<Form>
Expand Down Expand Up @@ -420,10 +420,10 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do

slot :inner_block, required: true

def button(%{ type: "submit" } = assigns) do
def button(%{ type: "submit" } = assigns, _interface) do
~LVN"""
<Section>
<LiveSubmitButton style={[
<LiveButton type="submit" style={[
"buttonStyle(.borderedProminent)",
"controlSize(.large)",
"listRowInsets(EdgeInsets())",
Expand All @@ -435,12 +435,12 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
]}>
<%= render_slot(@inner_block) %>
</Group>
</LiveSubmitButton>
</LiveButton>
</Section>
"""
end

def button(assigns) do
def button(assigns, _interface) do
~LVN"""
<Button {@rest}>
<%= render_slot(@inner_block) %>
Expand Down Expand Up @@ -474,7 +474,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do

slot :action, doc: "the slot for showing user actions in the last table column"

def table(assigns) do
def table(assigns, _interface) do
~LVN"""
<Table id={@id}>
<Group template="columns">
Expand Down Expand Up @@ -514,7 +514,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
attr :title, :string, required: true
end

def list(assigns) do
def list(assigns, _interface) do
~LVN"""
<List>
<LabeledContent :for={item <- @item}>
Expand All @@ -538,7 +538,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
attr :name, :string, required: true
attr :rest, :global

def icon(assigns) do
def icon(assigns, _interface) do
~LVN"""
<Image systemName={@name} {@rest} />
"""
Expand Down Expand Up @@ -592,7 +592,7 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
attr :style, :string
end

def image(assigns) do
def image(assigns, _interface) do
~LVN"""
<AsyncImage url={@url} {@rest}>
<Group template="phase.empty" :if={@empty != []}>
Expand All @@ -604,27 +604,27 @@ defmodule CookbookWeb.CoreComponents.SwiftUI do
"""
end

defp image_success(%{ slot: [%{ inner_block: nil }] } = assigns) do
defp image_success(%{ slot: [%{ inner_block: nil }] } = assigns, _interface) do
~LVN"""
<AsyncImage image template="phase.success" :for={slot <- @slot} class={Map.get(slot, :class)} {%{ style: Map.get(slot, :style) }} />
"""
end

defp image_success(assigns) do
defp image_success(assigns, _interface) do
~LVN"""
<Group template="phase.success" :if={@slot != []}>
<%= render_slot(@slot) %>
</Group>
"""
end

defp image_failure(%{ slot: [%{ inner_block: nil }] } = assigns) do
defp image_failure(%{ slot: [%{ inner_block: nil }] } = assigns, _interface) do
~LVN"""
<AsyncImage error template="phase.failure" :for={slot <- @slot} class={Map.get(slot, :class)} {%{ style: Map.get(slot, :style) }} />
"""
end

defp image_failure(assigns) do
defp image_failure(assigns, _interface) do
~LVN"""
<Group template="phase.failure" :if={@slot != []}>
<%= render_slot(@slot) %>
Expand Down
4 changes: 2 additions & 2 deletions lib/cookbook_web/components/layouts_swiftui/root.swiftui.neex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<.csrf_token />
<csrf-token value={Phoenix.Controller.get_csrf_token()}/>
<Style url={~p"/assets/app.swiftui.styles"} />
<NavigationStack>
<%= @inner_content %>
</NavigationStack>
</NavigationStack>
4 changes: 3 additions & 1 deletion lib/cookbook_web/live/cookbook_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ defmodule CookbookWeb.CookbookLive do
{:noreply,
socket
|> assign(:qr, qr)
|> assign(:uri, uri)}
|> assign(:uri, uri)
|> assign(:dead, connected?(socket))
|> assign(:count, 0)}
end

def mount(_params, _session, socket) do
Expand Down
10 changes: 8 additions & 2 deletions lib/cookbook_web/live/cookbook_live.swiftui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule CookbookWeb.CookbookLive.SwiftUI do
<ScrollView
axes="horizontal"
style={[
"scrollTargetBehavior(.viewAligned)",
"scrollTargetBehavior(.viewAligned(limitBehavior: .alwaysByOne))",
"scrollIndicators(.hidden)",
"safeAreaPadding(.horizontal, 16)",
"listRowInsets(EdgeInsets())",
Expand Down Expand Up @@ -70,6 +70,12 @@ defmodule CookbookWeb.CookbookLive.SwiftUI do
:for={recipe <- @recipes}
navigate={recipe.path}
>
<ProgressView
template="destination"
style="navigationTitle(:title)"
>
<Text template="title"><%= recipe.metadata.title %></Text>
</ProgressView>
<Label>
<VStack alignment="leading" template="title">
<Text><%= recipe.metadata.title %></Text>
Expand All @@ -85,7 +91,7 @@ defmodule CookbookWeb.CookbookLive.SwiftUI do

attr :recipe, :any
attr :hue, :float
def featured_recipe(assigns) do
def featured_recipe(assigns, _interface) do
~LVN"""
<.link navigate={@recipe.path} style="buttonStyle(.plain);">
<VStack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ defmodule CookbookWeb.DrillDownNavigationLive.SwiftUI do
navigate={~p"/recipes/drill-down-navigation?index=#{i}"}
>
Item <%= i %>

<VStack template="destination" style="navigationTitle(:title)">
<Text template="title"><%= i %></Text>
</VStack>
</.link>
</List>
"""
Expand Down
58 changes: 58 additions & 0 deletions lib/cookbook_web/live/recipes/file_upload_live.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
defmodule CookbookWeb.FileUploadLive do
use CookbookWeb, :live_view
use CookbookNative, :live_view

def mount(_params, _session, socket) do
{:ok, socket
|> assign(:uploaded_files, ["No files uploaded..."])
|> allow_upload(:avatar, accept: ~w(.png .jpg .jpeg), max_entries: 2)
|> assign(:show_file_picker, false)}
end

def render(assigns) do
~H""
end

def handle_event("toggle-file-picker", _params, socket) do
{:noreply, assign(socket, :show_file_picker, not socket.assigns.show_file_picker)}
end

@impl Phoenix.LiveView
def handle_event("validate", params, socket) do
{:noreply, assign(socket, :show_file_picker, false)}
end

@impl Phoenix.LiveView
def handle_event("cancel-upload", %{"ref" => ref}, socket) do
{:noreply, cancel_upload(socket, :avatar, ref)}
end

@impl Phoenix.LiveView
def handle_event("save", _params, socket) do
Process.send_after(self(), :tick, 10)
uploaded_files =
consume_uploaded_entries(socket, :avatar, fn %{path: path}, entry ->
dbg entry
{:ok, Path.basename(path)}
end)

{:noreply,
socket
|> update(:uploaded_files, &(&1 ++ uploaded_files))
}
end

def handle_info(:tick, socket) do
{:noreply, assign(
socket,
:uploaded_files,
(if length(socket.assigns.uploaded_files) == 1,
do: socket.assigns.uploaded_files,
else: tl(socket.assigns.uploaded_files))
)}
end

defp error_to_string(:too_large), do: "Too large"
defp error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
defp error_to_string(:too_many_files), do: "You have selected too many files"
end
Loading