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

Interactive Guides #65

Merged
merged 41 commits into from
Jan 26, 2024
Merged

Interactive Guides #65

merged 41 commits into from
Jan 26, 2024

Conversation

BrooklinJazz
Copy link
Contributor

@BrooklinJazz BrooklinJazz commented Nov 13, 2023

Overview

This PR introduces the following guides:

**Testing this PR requires the main version of Livebook. You can go here to install it using Escript: https://github.com/livebook-dev/livebook#escript

This PR also introduces the mix ex_doc_guides task, which formats the .livemd files into .md files. These .md files have content stripped and other formatting improvements, such as the run-in livebook badge.

@BrooklinJazz BrooklinJazz changed the title Interactive Guides [WIP] Interactive Guides Nov 30, 2023
@bcardarella
Copy link
Contributor

@BrooklinJazz this PR seems fine but I didn't do a content review. Let's do the content review on our call.

@BrooklinJazz BrooklinJazz changed the title Interactive Guides Interactive Guides [Bug Fixes Needed] Dec 1, 2023
Copy link
Contributor

@carson-katri carson-katri left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! I really like the "Your Turn" sections.

I think some other useful elements to include would be:

  • List - provides a system-specific interface, and has better performance for large amounts of scrolling elements
  • ScrollView - more customizable than list. This could also mention LazyVStack, LazyHStack, LazyVGrid, and LazyHGrid. These are crucial for performance when using ScrollView with large amounts of items, and should be preferred over VStack, HStack, and Grid for scrollable content.
  • TextField, Toggle, Stepper, DatePicker, and other form controls

guides/ex_doc_notebooks/getting-started.md Show resolved Hide resolved
guides/notebooks/create-a-swiftui-application.livemd Outdated Show resolved Hide resolved
guides/notebooks/create-a-swiftui-application.livemd Outdated Show resolved Hide resolved
guides/notebooks/create-a-swiftui-application.livemd Outdated Show resolved Hide resolved
guides/notebooks/create-a-swiftui-application.livemd Outdated Show resolved Hide resolved
guides/notebooks/swiftui-views.livemd Outdated Show resolved Hide resolved
guides/notebooks/swiftui-views.livemd Outdated Show resolved Hide resolved
guides/notebooks/swiftui-views.livemd Outdated Show resolved Hide resolved
guides/notebooks/swiftui-views.livemd Outdated Show resolved Hide resolved
guides/notebooks/swiftui-views.livemd Outdated Show resolved Hide resolved
@BrooklinJazz
Copy link
Contributor Author

BrooklinJazz commented Jan 2, 2024

This looks great! I really like the "Your Turn" sections.

I think some other useful elements to include would be:

  • List - provides a system-specific interface, and has better performance for large amounts of scrolling elements
  • ScrollView - more customizable than list. This could also mention LazyVStack, LazyHStack, LazyVGrid, and LazyHGrid. These are crucial for performance when using ScrollView with large amounts of items, and should be preferred over VStack, HStack, and Grid for scrollable content.
  • TextField, Toggle, Stepper, DatePicker, and other form controls

I've added everything except for the form controls, as they are covered in the event bindings/interactive views section.

@carson-katri
Copy link
Contributor

List Selection

def mount(_params, _session, socket) do
  {:ok, assign(socket, selection: "1")}
end

def render(assigns) do
  ~SWIFTUI"""
  <List selection={@selection} phx-change="selection-changed">
    <Text id={"#{i}"} :for={i <- 1..10}><%= i %></Text>
  </List>
  """
end

def handle_event("selection-changed", %{ "selection" => selection }, socket) do
  {:noreply, assign(socket, selection: selection)}
end

Hierarchical List (Disclosure Group)

<List>
  <DisclosureGroup>
    <Text template="label">Level 1</Text>
    <DisclosureGroup>
      <Text template="label">Level 2</Text>
      <DisclosureGroup>
        <Text template="label">Level 3</Text>
        Content
      </DisclosureGroup>
    </DisclosureGroup>
  </DisclosureGroup>
</List>

Hierarchical List (Section)

<List>
  <Section>
    <Text template="header">Header</Text>
    Content
    <Text template="footer">Footer</Text>
  </Section>
</List>

Refreshable List (requires liveview-native/liveview-client-swiftui#1212)

def render(assigns) do
  ~SWIFTUI"""
  <List class="refreshable">
    <Text id={"#{i}"} :for={i <- 1..10}><%= i %></Text>
  </List>
  """
end

def handle_event("refresh", _params, socket) do
  {:noreply, socket}
end

Stylesheet:

"refreshable" do
  refreshable(action: event("on-refresh"))
end

@BrooklinJazz
Copy link
Contributor Author

List Selection

def mount(_params, _session, socket) do
  {:ok, assign(socket, selection: "1")}
end

def render(assigns) do
  ~SWIFTUI"""
  <List selection={@selection} phx-change="selection-changed">
    <Text id={"#{i}"} :for={i <- 1..10}><%= i %></Text>
  </List>
  """
end

def handle_event("selection-changed", %{ "selection" => selection }, socket) do
  {:noreply, assign(socket, selection: selection)}
end

Hierarchical List (Disclosure Group)

<List>
  <DisclosureGroup>
    <Text template="label">Level 1</Text>
    <DisclosureGroup>
      <Text template="label">Level 2</Text>
      <DisclosureGroup>
        <Text template="label">Level 3</Text>
        Content
      </DisclosureGroup>
    </DisclosureGroup>
  </DisclosureGroup>
</List>

Hierarchical List (Section)

<List>
  <Section>
    <Text template="header">Header</Text>
    Content
    <Text template="footer">Footer</Text>
  </Section>
</List>

Refreshable List (requires liveview-native/liveview-client-swiftui#1212)

def render(assigns) do
  ~SWIFTUI"""
  <List class="refreshable">
    <Text id={"#{i}"} :for={i <- 1..10}><%= i %></Text>
  </List>
  """
end

def handle_event("refresh", _params, socket) do
  {:noreply, socket}
end

Stylesheet:

"refreshable" do
  refreshable(action: event("on-refresh"))
end

@carson-katri Thank you for the help with examples.

Do we have a way of supporting multiple selection?

@carson-katri
Copy link
Contributor

@BrooklinJazz Good question, we used to support it with native_binding. Looks like some updates are needed to get it working with phx-change though. I'll look into this.

@BrooklinJazz BrooklinJazz mentioned this pull request Jan 16, 2024
@BrooklinJazz BrooklinJazz changed the title Interactive Guides [Bug Fixes Needed] Interactive Guides Jan 16, 2024
@BrooklinJazz BrooklinJazz changed the base branch from main to v0.2.0 January 26, 2024 00:38
@BrooklinJazz BrooklinJazz merged commit 3791cef into v0.2.0 Jan 26, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants