Openswiftui
OpenSwiftui是Apple Swiftui DSL(特定領域)的OpenSource實現。
該項目的目標是盡可能靠近原始API。
目前,該項目正在早期開發中。
背景
蘋果在WWDC 19上介紹了Swiftui。從那時起,使用圖形用戶界面的開發應用程序變得更加舒適地讀寫,寫入和維護。不幸的是,“一次學習,應用到任何地方”的原則僅在Apple平台上起作用。
Swift在Apple平台,Web,Linux,Windows,甚至在嵌入式設備上運行。如果您可以在運行Swift的平台上與SwiftUI一起編寫基於GUI的應用程序,那不是很好嗎?
平台上的swiftui
OpenSwiftui提供了API - 其他項目可以針對Linux,Windows,Embedded等不同平台實施UI元素的實際渲染。
Swiftuiembedded是使用OpenSwiftui(Demo)的第一批項目之一。
貢獻
隨著時間的流逝和集體猜測,應該可以從Apple重新創建完整的Swiftui API。檢查狀態概述以查看缺少或需要完成的內容。
一個好的起點是熟悉SwiftUI接口,專注於某些功能,並嘗試重新實現它。一個有用的工具是使用反射( Mirror(reflecting: …) )窺視SwiftUI類型和實例。這揭示了實例的內部結構(屬性,類型,名稱和繼承)。
實施缺失的作品後,請隨時提出拉動請求。
請注意:
Swiftui的私人方法和屬性應由_ (下劃線)前綴,並在OpenSwiftUI中標記為公共。這樣做是必要的,因為前端可能需要訪問。
需要XCode 11.2或更高。
地位
視圖和控件
要點
文字
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct Text | |
| struct TextField | |
| struct SecureField | |
| ✅ | struct Font | |
圖像
| 地位 | 姓名 | 筆記 |
|---|
| 配x | struct Image | CGIMAGE不支持 |
按鈕
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct Button | |
| struct NavigationLink | |
| struct MenuButton | |
| struct EditButton | |
| struct PasteButton | |
價值選擇器
| 地位 | 姓名 | 筆記 |
|---|
| struct Toggle | |
| 配x | struct Picker | |
| struct DatePicker | |
| struct Slider | |
| 配x | struct Stepper | |
支持類型
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct ViewBuilder | |
| ✅ | protocol ViewModifier | |
查看佈局和演示文稿
堆棧
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct HStack | |
| ✅ | struct VStack | |
| ✅ | struct ZStack | |
列表和滾動視圖
| 地位 | 姓名 | 筆記 |
|---|
| struct List | |
| protocol DynamicViewContent | |
| ✅ | protocol Identifiable | 由Swift提供。 |
| ✅ | struct ForEach | |
| struct ScrollView | |
| 配x | enum Axis | |
容器視圖
| 地位 | 姓名 | 筆記 |
|---|
| struct Form | |
| 配x | struct Group | |
| struct GroupBox | |
| struct Section | |
墊片和分隔線
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct Spacer | |
| ✅ | struct Divider | |
建築景觀
| 地位 | 姓名 | 筆記 |
|---|
| struct NavigationView | |
| struct TabView | |
| struct HSplitView | |
| struct VSplitView | |
演講
| 地位 | 姓名 | 筆記 |
|---|
| struct Alert | |
| struct ActionSheet | |
有條件可見的物品
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct EmptyView | |
| struct EquatableView | |
很少使用的視圖
| 地位 | 姓名 | 筆記 |
|---|
| 配x | struct AnyView | init?(_fromValue value: Any)丟失。 |
| ✅ | struct TupleView | |
繪畫和動畫
要點
動畫片
| 地位 | 姓名 | 筆記 |
|---|
| struct Animation | |
| protocol Animatable | |
| protocol AnimatableModifier | |
| func withAnimation<Result>(Animation?, () -> Result) -> Result | |
| struct AnimationPair | |
| struct EmptyAnimationData | |
| struct AnyTransition | |
形狀
| 地位 | 姓名 | 筆記 |
|---|
| 配x | struct Rectangle | |
| ✅ | enum Edge | |
| struct RoundedRectangle | |
| 配x | struct Circle | |
| struct Ellipse | |
| struct Capsule | |
| struct Path | |
變形的形狀
| 地位 | 姓名 | 筆記 |
|---|
| protocol InsettableShape | |
| struct ScaledShape | |
| struct RotatedShape | |
| struct OffsetShape | |
| struct TransformedShape | |
油漆,樣式和漸變
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | 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 | |
幾何學
| 地位 | 姓名 | 筆記 |
|---|
| struct GeometryProxy | |
| struct GeometryReader | |
| protocol GeometryEffect | |
| struct Angle | |
| struct Anchor | |
| struct UnitPoint | |
| enum CoordinateSpace | |
| struct ProjectionTransform | |
| protocol VectorArithmetic | |
狀態和數據流
綁定
與數據有關的視圖
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct State | |
| struct ObservedObject | |
| struct EnvironmentObject | |
| struct FetchRequest | |
| struct FetchedResults | |
| 配x | protocol DynamicProperty | func update()缺失。 |
環境價值
| 地位 | 姓名 | 筆記 |
|---|
| ✅ | struct Environment | |
| ✅ | struct EnvironmentValues | |
偏好
| 地位 | 姓名 | 筆記 |
|---|
| protocol PreferenceKey | |
| struct LocalizedStringKey | |
交易
手勢
基本手勢
| 地位 | 姓名 | 筆記 |
|---|
| struct TapGesture | |
| struct LongPressGesture | |
| struct DragGesture | |
| struct MagnificationGesture | |
| struct RotationGesture | |
聯合手勢
| 地位 | 姓名 | 筆記 |
|---|
| struct SequenceGesture | |
| struct SimultaneousGesture | |
| struct ExclusiveGesture | |
自定義手勢
| 地位 | 姓名 | 筆記 |
|---|
| protocol Gesture | |
| struct AnyGesture | |
動態視圖屬性
| 地位 | 姓名 | 筆記 |
|---|
| struct GestureState | |
| struct GestureStateGesture | |
手勢支持
| 地位 | 姓名 | 筆記 |
|---|
| struct GestureMask | |
| struct EventModifiers | |
傳奇
資源
Swiftui接口
與您在Xcode中看到的相比,此要旨不僅顯示了公共接口。它顯示了私有屬性,以及@inlinable標記的屬性,功能和初始化器的主體。
/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是HelgeHeß的SwiftUi實施Swiftui。該項目的目標僅專注於網絡。它通過在這里和那裡進行一些快捷方式來偏離Swiftui,但功能看起來很完整,非常適合靈感。
Swiftui符號
此命令通過llvm-mn實用程序打印SwiftUi的符號表。
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 '
您還可以看一下這個要旨。
鏈接
- SwiftUi @viewbuilder結果是一個tupleview,Apple如何使用它並避免將事物變成Anyview?
- https://stackoverflow.com/questions/56434549/what-enables-swiftuis-dsl
- 使用Swiftui建立自定義景觀
- Swiftui Essentials
- 通過Swiftui的數據流
- 介紹Swiftui:構建您的第一個應用程序
- 所有設備上的Swiftui
特別感謝
我要特別感謝HelgeHeß。他創建了SwiftWebui,為Openswiftui貢獻了許多建議,並幫助了他的發現的見解。
接觸
- Devran“ Cosmo” Uenal
- Twitter:@maccosmo
- LinkedIn:Devranuenal
執照
OpenSwiftui是根據MIT許可發布的。