Cosmo/OpenSwiftUI

WIP — OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL.

Swift

1,439

95 commits

updated Oct 19, 2020

See the code

README

OpenSwiftUI

OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL (Domain-specific language).

The project's goal is to stay close to the original API as possible.

Currently, this project is in early development.

Background

Apple introduced SwiftUI at WWDC 19. Since then, developing applications with graphical user interfaces became more comfortable to read, write, and maintain. Unfortunately, the principle "Learn once, apply anywhere" works on Apple platforms, only.

Swift runs on Apple platforms, the web, Linux, Windows, and even on embedded devices. Wouldn't it be great if you could write GUI based applications with SwiftUI on platforms that run Swift?

SwiftUI on your platform

OpenSwiftUI provides the API — other projects can implement the actual rendering of UI elements for different platforms like Linux, Windows, Embedded, and many more.

SwiftUIEmbedded is one of the first projects that make use of OpenSwiftUI (Demo).

Demo

Contributing

Over time and collective guesswork, it should be possible to re-create the complete SwiftUI API from Apple. Check the Status overview to see what's missing or needs to be completed.

A good starting point is to get familiar with the SwiftUI interface, focus on certain functionality, and try to re-implement it. A helpful tool is to use reflection (Mirror(reflecting: …)) to peek into SwiftUI types and instances. This reveals the internal structure of instances (properties, types, names and inheritance).

Once you implemented a missing piece, please feel free to contribute a pull request.

Please note:

Private methods and properties of SwiftUI should be prefixed by an _ (underscore) and marked as public in OpenSwiftUI. Doing this is necessary because the frontend might need access.

Xcode 11.2 or higher is required.

Status

Views and Controls

Essentials

StatusNameNotes
✅protocol View

Text

StatusNameNotes
✅struct Text
❌struct TextField
❌struct SecureField
✅struct Font

Images

StatusNameNotes
⚠️struct ImageCGImage not supported

Buttons

StatusNameNotes
✅struct Button
❌struct NavigationLink
❌struct MenuButton
❌struct EditButton
❌struct PasteButton

Value Selectors

StatusNameNotes
❌struct Toggle
⚠️struct Picker
❌struct DatePicker
❌struct Slider
⚠️struct Stepper

Supporting Types

StatusNameNotes
✅struct ViewBuilder
✅protocol ViewModifier

View Layout and Presentation

Stacks

StatusNameNotes
✅struct HStack
✅struct VStack
✅struct ZStack

Lists and Scroll Views

StatusNameNotes
❌struct List
❌protocol DynamicViewContent
✅protocol IdentifiableProvided by Swift.
✅struct ForEach
❌struct ScrollView
⚠️enum Axis

Container Views

StatusNameNotes
❌struct Form
⚠️struct Group
❌struct GroupBox
❌struct Section

Spacer and Dividers

StatusNameNotes
✅struct Spacer
✅struct Divider

Architectural Views

StatusNameNotes
❌struct NavigationView
❌struct TabView
❌struct HSplitView
❌struct VSplitView

Presentations

StatusNameNotes
❌struct Alert
❌struct ActionSheet

Conditionally Visible Items

StatusNameNotes
✅struct EmptyView
❌struct EquatableView

Infrequently Used Views

StatusNameNotes
⚠️struct AnyViewinit?(_fromValue value: Any) missing.
✅struct TupleView

Drawing and Animation

Essentials
StatusNameNotes
⚠️protocol Shape

Animation

StatusNameNotes
❌struct Animation
❌protocol Animatable
❌protocol AnimatableModifier
❌func withAnimation<Result>(Animation?, () -> Result) -> Result
❌struct AnimationPair
❌struct EmptyAnimationData
❌struct AnyTransition

Shapes

StatusNameNotes
⚠️struct Rectangle
✅enum Edge
❌struct RoundedRectangle
⚠️struct Circle
❌struct Ellipse
❌struct Capsule
❌struct Path

Transformed Shapes

StatusNameNotes
❌protocol InsettableShape
❌struct ScaledShape
❌struct RotatedShape
❌struct OffsetShape
❌struct TransformedShape

Paints, Styles, and Gradients

StatusNameNotes
✅struct Color
❌struct ImagePaint
❌struct Gradient
❌struct LinearGradient
❌struct AngularGradient
❌struct RadialGradient
❌struct ForegroundStyle
❌struct FillStyle
❌protocol ShapeStyle
❌enum RoundedCornerStyle
❌struct SelectionShapeStyle
❌struct SeparatorShapeStyle
❌struct StrokeStyle

Geometry

StatusNameNotes
❌struct GeometryProxy
❌struct GeometryReader
❌protocol GeometryEffect
❌struct Angle
❌struct Anchor
❌struct UnitPoint
❌enum CoordinateSpace
❌struct ProjectionTransform
❌protocol VectorArithmetic

State and Data Flow

Bindings

StatusNameNotes
⚠️struct Binding

Data-Dependent Views

StatusNameNotes
✅struct State
❌struct ObservedObject
❌struct EnvironmentObject
❌struct FetchRequest
❌struct FetchedResults
⚠️protocol DynamicPropertyfunc update() missing.

Environment Values

StatusNameNotes
✅struct Environment
✅struct EnvironmentValues

Preferences

StatusNameNotes
❌protocol PreferenceKey
❌struct LocalizedStringKey

Transactions

StatusNameNotes
❌struct Transaction

Gestures

Basic Gestures

StatusNameNotes
❌struct TapGesture
❌struct LongPressGesture
❌struct DragGesture
❌struct MagnificationGesture
❌struct RotationGesture

Combined Gestures

StatusNameNotes
❌struct SequenceGesture
❌struct SimultaneousGesture
❌struct ExclusiveGesture

Custom Gesture

StatusNameNotes
❌protocol Gesture
❌struct AnyGesture

Dynamic View Properties

StatusNameNotes
❌struct GestureState
❌struct GestureStateGesture

Gesture Support

StatusNameNotes
❌struct GestureMask
❌struct EventModifiers

Legend

SymbolDescription
✅Done
❌Open
⚠️Incomplete

Resources

SwiftUI Interface

Compared to what you can see in Xcode, this gist shows you more than just the public interfaces. It shows private properties, and the body of @inlinable marked properties, functions, and initializers.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/SwiftUI.framework/Versions/A/Modules/SwiftUI.swiftmodule/x86_64.swiftinterface

SwiftWebUI

SwiftWebUI is an implementation of SwiftUI for the web by Helge Heß. This project's goal is focused exclusively on the web. It deviates a little bit from SwiftUI by taking some shortcuts here and there -- but looks quite complete in functionality and is great for inspiration.

SwiftUI symbols

This command prints the symbol table of SwiftUI via the llvm-mn utility.

nm -gUj /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUI.framework/SwiftUI | swift-demangle | sed 's/SwiftUI.//g' | sed 's/Swift.//g'

You can also have a look at this gist instead.

Special thanks

I want to give special thanks to Helge Heß. He created SwiftWebUI, contributed many suggestions to OpenSwiftUI, and helped with insights of his findings.


Contact

License

OpenSwiftUI is released under the MIT License.

apple-swiftui-dsl
embedded
hacktoberfest
linux
opensource
raspberry-pi
swift
swiftui
windows

Cosmo/OpenSwiftUI

WIP — OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL.

Swift

1,439

95 commits

updated Oct 19, 2020

See the code

README

OpenSwiftUI

OpenSwiftUI is an OpenSource implementation of Apple's SwiftUI DSL (Domain-specific language).

The project's goal is to stay close to the original API as possible.

Currently, this project is in early development.

Background

Apple introduced SwiftUI at WWDC 19. Since then, developing applications with graphical user interfaces became more comfortable to read, write, and maintain. Unfortunately, the principle "Learn once, apply anywhere" works on Apple platforms, only.

Swift runs on Apple platforms, the web, Linux, Windows, and even on embedded devices. Wouldn't it be great if you could write GUI based applications with SwiftUI on platforms that run Swift?

SwiftUI on your platform

OpenSwiftUI provides the API — other projects can implement the actual rendering of UI elements for different platforms like Linux, Windows, Embedded, and many more.

SwiftUIEmbedded is one of the first projects that make use of OpenSwiftUI (Demo).

Demo

Contributing

Over time and collective guesswork, it should be possible to re-create the complete SwiftUI API from Apple. Check the Status overview to see what's missing or needs to be completed.

A good starting point is to get familiar with the SwiftUI interface, focus on certain functionality, and try to re-implement it. A helpful tool is to use reflection (Mirror(reflecting: …)) to peek into SwiftUI types and instances. This reveals the internal structure of instances (properties, types, names and inheritance).

Once you implemented a missing piece, please feel free to contribute a pull request.

Please note:

Private methods and properties of SwiftUI should be prefixed by an _ (underscore) and marked as public in OpenSwiftUI. Doing this is necessary because the frontend might need access.

Xcode 11.2 or higher is required.

Status

Views and Controls

Essentials

StatusNameNotes
✅protocol View

Text

StatusNameNotes
✅struct Text
❌struct TextField
❌struct SecureField
✅struct Font

Images

StatusNameNotes
⚠️struct ImageCGImage not supported

Buttons

StatusNameNotes
✅struct Button
❌struct NavigationLink
❌struct MenuButton
❌struct EditButton
❌struct PasteButton

Value Selectors

StatusNameNotes
❌struct Toggle
⚠️struct Picker
❌struct DatePicker
❌struct Slider
⚠️struct Stepper

Supporting Types

StatusNameNotes
✅struct ViewBuilder
✅protocol ViewModifier

View Layout and Presentation

Stacks

StatusNameNotes
✅struct HStack
✅struct VStack
✅struct ZStack

Lists and Scroll Views

StatusNameNotes
❌struct List
❌protocol DynamicViewContent
✅protocol IdentifiableProvided by Swift.
✅struct ForEach
❌struct ScrollView
⚠️enum Axis

Container Views

StatusNameNotes
❌struct Form
⚠️struct Group
❌struct GroupBox
❌struct Section

Spacer and Dividers

StatusNameNotes
✅struct Spacer
✅struct Divider

Architectural Views

StatusNameNotes
❌struct NavigationView
❌struct TabView
❌struct HSplitView
❌struct VSplitView

Presentations

StatusNameNotes
❌struct Alert
❌struct ActionSheet

Conditionally Visible Items

StatusNameNotes
✅struct EmptyView
❌struct EquatableView

Infrequently Used Views

StatusNameNotes
⚠️struct AnyViewinit?(_fromValue value: Any) missing.
✅struct TupleView

Drawing and Animation

Essentials
StatusNameNotes
⚠️protocol Shape

Animation

StatusNameNotes
❌struct Animation
❌protocol Animatable
❌protocol AnimatableModifier
❌func withAnimation<Result>(Animation?, () -> Result) -> Result
❌struct AnimationPair
❌struct EmptyAnimationData
❌struct AnyTransition

Shapes

StatusNameNotes
⚠️struct Rectangle
✅enum Edge
❌struct RoundedRectangle
⚠️struct Circle
❌struct Ellipse
❌struct Capsule
❌struct Path

Transformed Shapes

StatusNameNotes
❌protocol InsettableShape
❌struct ScaledShape
❌struct RotatedShape
❌struct OffsetShape
❌struct TransformedShape

Paints, Styles, and Gradients

StatusNameNotes
✅struct Color
❌struct ImagePaint
❌struct Gradient
❌struct LinearGradient
❌struct AngularGradient
❌struct RadialGradient
❌struct ForegroundStyle
❌struct FillStyle
❌protocol ShapeStyle
❌enum RoundedCornerStyle
❌struct SelectionShapeStyle
❌struct SeparatorShapeStyle
❌struct StrokeStyle

Geometry

StatusNameNotes
❌struct GeometryProxy
❌struct GeometryReader
❌protocol GeometryEffect
❌struct Angle
❌struct Anchor
❌struct UnitPoint
❌enum CoordinateSpace
❌struct ProjectionTransform
❌protocol VectorArithmetic

State and Data Flow

Bindings

StatusNameNotes
⚠️struct Binding

Data-Dependent Views

StatusNameNotes
✅struct State
❌struct ObservedObject
❌struct EnvironmentObject
❌struct FetchRequest
❌struct FetchedResults
⚠️protocol DynamicPropertyfunc update() missing.

Environment Values

StatusNameNotes
✅struct Environment
✅struct EnvironmentValues

Preferences

StatusNameNotes
❌protocol PreferenceKey
❌struct LocalizedStringKey

Transactions

StatusNameNotes
❌struct Transaction

Gestures

Basic Gestures

StatusNameNotes
❌struct TapGesture
❌struct LongPressGesture
❌struct DragGesture
❌struct MagnificationGesture
❌struct RotationGesture

Combined Gestures

StatusNameNotes
❌struct SequenceGesture
❌struct SimultaneousGesture
❌struct ExclusiveGesture

Custom Gesture

StatusNameNotes
❌protocol Gesture
❌struct AnyGesture

Dynamic View Properties

StatusNameNotes
❌struct GestureState
❌struct GestureStateGesture

Gesture Support

StatusNameNotes
❌struct GestureMask
❌struct EventModifiers

Legend

SymbolDescription
✅Done
❌Open
⚠️Incomplete

Resources

SwiftUI Interface

Compared to what you can see in Xcode, this gist shows you more than just the public interfaces. It shows private properties, and the body of @inlinable marked properties, functions, and initializers.

/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/SwiftUI.framework/Versions/A/Modules/SwiftUI.swiftmodule/x86_64.swiftinterface

SwiftWebUI

SwiftWebUI is an implementation of SwiftUI for the web by Helge Heß. This project's goal is focused exclusively on the web. It deviates a little bit from SwiftUI by taking some shortcuts here and there -- but looks quite complete in functionality and is great for inspiration.

SwiftUI symbols

This command prints the symbol table of SwiftUI via the llvm-mn utility.

nm -gUj /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/SwiftUI.framework/SwiftUI | swift-demangle | sed 's/SwiftUI.//g' | sed 's/Swift.//g'

You can also have a look at this gist instead.

Special thanks

I want to give special thanks to Helge Heß. He created SwiftWebUI, contributed many suggestions to OpenSwiftUI, and helped with insights of his findings.


Contact

License

OpenSwiftUI is released under the MIT License.

apple-swiftui-dsl
embedded
hacktoberfest
linux
opensource
raspberry-pi
swift
swiftui
windows

Significant stargazers

Whyrusleeping

1,795 followers · starred Jan 2021

Eloy Durán

1,366 followers · starred Jul 2020

Marco Munizaga

253 followers · starred Dec 2019

Alex Akers

995 followers · starred Nov 2019