• Stars
    star
    87
  • Rank 378,873 (Top 8 %)
  • Language
    Swift
  • License
    MIT License
  • Created almost 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Create SwiftUI preview variants for macOS, iOS, tvOS, and watchOS with ease

🎭 Gala

Gala is a Swift Package Manager project for macOS, iOS, tvOS, and watchOS to help you create SwiftUI preview variants.

Say for instance you want to render your preview in both light and dark mode, you can use NightAndDay:

   static var previews: some View {
       NightAndDay {
           ContentView()
       }
   }

Gala demo

Without Gala, this would have to be written as

    static var previews: some View {
        Group {
            ContentView()
                .environment(\.colorScheme, .light)

            ContentView()
                .environment(\.colorScheme, .dark)
        }
    }

or

    static var previews: some View {
        ForEach(ColorScheme.allCases, id: \.self) { scheme in
            ContentView()
        }
    }

However, Gala doesn't stop there. It also offers a few other "attribute iterators":

  • ContentSizeCategories
  • HorizontalSizeClasses
  • LayoutDirections
  • LegibilityWeights
  • VerticalSizeClasses

Just substitute them in for NightAndDay:

   static var previews: some View {
       LayoutDirections {
           ContentView()
       }
   }

Layouts

In addition, you can iterate over a given set of layouts as follows:

    static var previews: some View {
        Layouts([.fixed(width: 200, height: 150), .sizeThatFits, .device]) {
                ContentView()
        }
    }

This is convenient if you have a set of frames you want to set your view up with.

Devices

You can also pass in a set of devices to the Device iterator:

    static var previews: some View {
        Devices([.iPhoneX, .iPhone11]) {
                ContentView()
        }
    }

Thanks to autocompletion you don't have to remember the precise names. Please note that particular care has been taken to transform Apple's fantastic product names into identifiers. For instance:

  • iPadPro9Β·7inch
  • iPhoneXΚ€
  • appleWatchSeries5﹘40mm

Thanks to Swift's support of unicode identifiers you can use these (and thanks to autocomplete you can actually enter them πŸ˜…).

You can also use Devices.iPhones (iPads, watches, tvs) to preview all of them:

    static var previews: some View {
        Devices(.iPhones) {
                ContentView()
        }
    }

Please note that these can take a while to render though, so it's not something that's advisable for a screen you use a lot. But it's a great use for a separate file where you set up marketing shots and want them for the full set of devices.

Name parameter

All iterators take an optional name parameter which will add a previewDisplayName with the name and a description of the attribute to the preview.

Contributing

Please fork and submit pull requests if you find any issues or come up with improvements or extensions.

You can reach me at via Twitter or email.

More Repositories

1

Arena

A command line tool to create Swift Playground projects with SPM package dependencies
Swift
678
star
2

CoPilot

Swift
275
star
3

Hummingbird

A macOS utility that makes window management a breeze
Swift
191
star
4

Historian

History viewer and transmitter for Composable Architecture apps
Swift
55
star
5

Rester

A command line tool to test (REST) APIs
Swift
42
star
6

blogpost-prometheus

Source code for blog post 'Monitoring with Prometheus, Grafana & Docker'
Dockerfile
19
star
7

PFCompArch

This is an example project for the "Composable Architecture" introduced by pointfree.co
Swift
14
star
8

ImageAttributesPublishPlugin

A Publish plugin to add support for image attributes
Swift
8
star
9

DiffMatchPatch

Swift package for Google’s Diff Match Patch
Objective-C
7
star
10

CRabbitMQ

A swift package manager wrapper for rabbitmq-c
C
6
star
11

ValueCodable

A Value struct to decode arbitrary data
Swift
6
star
12

autotm

Script that automatically switches between several configured time machine backup servers
Ruby
6
star
13

homebrew-tap

Ruby
3
star
14

Sms2Mail

Upload iPhone SMS (text messages) to an IMAP mail account
Python
3
star
15

Parser

Library to create composable parsers, based on pointfree.co's series on Parsing
Swift
3
star
16

CompArch

SwiftUI State-Action-Reducer architecture based on pointfree.co series
Swift
2
star
17

RabbitMQ

ObjC Framework wrapper for rabbitmq-c
C
2
star
18

couchdb-migration

Python
2
star
19

HistoryTransceiver

Swift
2
star
20

AsyncTest

SenTestCase+Async category and usage example
Objective-C
2
star
21

HastyHare

Swift wrapper for RabbitMQ C client rabbitmq-c
Swift
2
star
22

swift-pg-extras

Commands providing shortcuts to common Postgres introspection queries (Swift port of heroku-pg-extras)
Swift
2
star
23

homebrew-Hummingbird

Cask for Hummingbird
Ruby
2
star
24

sswg-package-lists

1
star
25

debug-2227

Swift
1
star
26

Hourglass-Mobile

Objective-C
1
star
27

vapor-lockup-repro

Test project to reproduce a lockup in Vapor
Swift
1
star
28

daws-test

Test project for WebSocketActors
Swift
1
star
29

SASPopupButton

Objective-C
1
star
30

Graf

Objective-C
1
star
31

MiteTime

Ruby
1
star
32

GrafServer

Python
1
star
33

Shooter

SpriteKit mini-game in swift (converted from Objective-C) with a Christmas theme
Swift
1
star
34

Sono

Sonography for iPad
Objective-C
1
star
35

Whiteboard

Objective-C
1
star
36

Tracker

Ruby
1
star
37

HeadPhoneJack

Swift
1
star
38

swift-package-collection-model

Swift
1
star
39

Capio

Capacity Management Front-end
JavaScript
1
star
40

GrafWeb

Graf web front-end
JavaScript
1
star
41

hummingbird-lockup-repro

Swift
1
star
42

Anjin

Sales rep application
Objective-C
1
star
43

builder-test-project

Test project for SPI builder
Swift
1
star
44

AbsReader

Objective-C
1
star
45

Sally

EK/VK Calculator
Objective-C
1
star
46

Hourglass

Objective-C
1
star
47

fs-html

A Swift DSL to generate HTML for use in server side swift projects - or anywhere you want to write type checked HTML.
Swift
1
star
48

LongRunningLazyInit

Objective-C
1
star
49

CouchStore2

Objective-C
1
star
50

Rester-sitemap

Swift script to create a restfile from sitemap.xml for use with Rester
Swift
1
star
51

jenkins-email-templates

1
star
52

dependencies-hang-repro

Swift
1
star
53

elme

Objective-C
1
star
54

Persequor

Ruby
1
star
55

pg-perf-regression

Swift
1
star