GithubHelp home page GithubHelp logo

picasso's Introduction

image (currently using Xcode Cloud)

Picasso

JSON โ†’ Native SwiftUI ๐ŸŽ‰

Eventually also:

  1. Swift on the server โ†’ Native SwiftUI
  2. JSON or Swift on the server โ†’ Jetpack Compose
image

Usage

  1. Clone or download the repo.
  2. Run ./build_framework.sh
  3. Grab the framework from _build_framework/PicassoKit.xcframework and drag into your Xcode project.
  4. Add AnyCodable as a dependency to your target.

Getting Started

  1. import PicassoKit

  2. Provide an encoder and decoder: Parser.shared = Parser(encoder: ..., decoder: ...). Picasso is tested on 3 options:

    1. ZippyJSON for decoding (pair with Apple's JSONEncoder).
    2. Apple's JSONDecoder and JSONEncoder.
    3. MessagePacker for MessagePack support.
  3. Create a PicassoView anywhere in your SwiftUI code:

    struct MyCoolView: View {
        var body: some View {
          VStack {
            Text("Hello!")
            PicassoView(URL("my.server.com/picasso/coolcontent")!) // <--
          }
        }
    }

Building Payload

Instead of typing the view hierarchy in JSON yourself (or if you want to use MessagePack), construct your UI from various PC views (PCStack, PCText etc.) and encode the main view:

func someView() -> PCStackView {
  PCStackView(...)
}

let view = someView()
let data = try someEncoder.encode(view)
let json = String(data: data, encoding: .utf8)
// upload the result json to your backend etc.

JSON Syntax

While not a comprehensive guide, this should provide an idea of how the JSON syntax looks like:

{
  "VStack": [
    {
      "text": "Hello!",
      "modifiers": {
        "font": { "weight": "bold", "style": "title" },
        "padding": { "top": 30, "leading": 100 }
      }
    },
    {
      "HStack": [...other views...],
      "alignment": "bottomTrailing",
      "modifiers": {
        "overlay": {
          "alignment": "bottom",
          "content": {...some view...}
        }
      }
    },
    {
      "optional": {
        "content": { "text": "Hi there! :)" },
        "presentationFlag": "show-text" }
    },
    {
      "button": "Toggle Hidden Text",
      "toggleFlag": "show-text",
    },
    {
      "image": "https://picsum.photos/200/400",
      "scale": 2
    }
  ]
}

ToDo/Reminders

(beyond the obvious missing stuff...)

  • Eventually split Parser/modifiers(from:) to categories: text, etc.
  • Remove the SwiftUI.View conformance from the types, make it separate (to later compile on Linux)
  • Find a way to type erase the modifiers like AnyPCView?
  • Somehow single pass on the JSON?
  • Fix the .indices in containers body (stack and scrollview)
  • Add MessagePack with perf tests against JSON
  • Figure out the crash in msgpack-swift when trying to parse modifiers (bug in the library)

picasso's People

Contributors

avielg avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.