SwiftUI components and extensions that seem to be highly reusable

Overview

SwiftUI-Common

SwiftUI components and extensions that seem to be highly reusable.

Since this is an experimental library, we recommend that you copy (or use as refererence) and use the source.

View

Modifier

Protocol

Extension

  • SwiftUI
    • View
      • toggleSidebar()
      • hideKeyboard()
      • when() { view in ... }
    • ViewModifier
      • toggleSidebar()
      • hideKeyboard()
    • Binding
      • optionalBinding() -> Binding
      • sliderBinding() -> Binding where Value: SliderValue
  • AppKit
  • UIKit
  • Foundation
    • Task
      • sleep(seconds: UInt64) async throws
      • sleep(milliseconds: UInt64) async throws

Install

If you want.

", dependencies: [ .product(name: "SwiftUICommon", package: "SwiftUI-Common"), ]), ] )">
let package = Package(
    dependencies: [
        .package(url: "https://github.com/YusukeHosonuma/SwiftUI-Common.git", from: "0.3.0"),
    ],
    targets: [
        .target(name: "", dependencies: [
             .product(name: "SwiftUICommon", package: "SwiftUI-Common"),
        ]),
    ]
)

Links

Author

Yusuke Hosonuma / @tobi462

Comments
  • Update View+Extension

    Update View+Extension

    View+Extensionにレイアウトに関する関数を実装しました。

    @YusukeHosonuma
    初めまして、TwitterでのiOS/SwiftUIに関する情報発信にいつも感謝しております。 私がSwiftUIの開発で普段使っているものをご提案させていただければかと思います。 (といっても、いつもチェックしている海外サイトのコピーコードなのですが。)

    引用元

    https://kavsoft.dev/

    opened by bamboo-wood 3
  • View+Layer: invertedMask()

    View+Layer: invertedMask()

    struct ContentView: View {
        var body: some View {
              Color.blue
                  .invertedMask {
                      Image(systemName: "swift")
                          .resizable()
                          .scaledToFit()
                          .frame(width: 200, height: 200)
                  }
        }
    }
    
    image
    opened by YusukeHosonuma 0
  • add: View+Notification

    add: View+Notification

    struct ContentView: View {
        var body: some View {
            Text("Hello")
                .onReceive(notification: UIScene.didEnterBackgroundNotification) { notification in
                    print("\(notification)")
                }
        }
    }
    
    opened by YusukeHosonuma 0
  • `alert(error: $error)`

    `alert(error: $error)`

    struct AlertView: View {
        @State var error: MyError? = nil
    
        var body: some View {
            VStack {
                ControlGroup {
                    Button("Warning") { error = .warning }
                    Button("Fatal") { error = .fatal }
                }
                .padding()
            }
            .alert(error: $error) {} // ✅
        }
    }
    
    opened by YusukeHosonuma 0
  • add: `printOnChange()`

    add: `printOnChange()`

    //
    // ✅ Print `offset` when it changed.
    //
    .printOnChange("🍎") { offset }
    //
    // ☑️ Equivalent to the following.
    //
    .onChange(of: offset) {
        print("🍎\($0)")
    }
    
    opened by YusukeHosonuma 0
  • add: onChangeSize()

    add: onChangeSize()

    e.g.

    image
        .onChangeSize {
            imageSize = Self.calculateImageSize(
                bounds: geometry.size,
                originalSize: $0,
                contentMode: contentMode
            )
        }
    
    opened by YusukeHosonuma 0
  • add: `ResizableImage`

    add: `ResizableImage`

    ResizableImage

    Resize only if the area overflows. (show as original-size if it included in area)

    • View
      • original(or contentMode: ContentMode) -> some View

    Extension

    • CGSize
      • contains(_ other: CGSize) -> Bool
    • View
      • frame(size: CGSize?) -> some View
      • sizePreference() -> some View
      • onChangeSizePreference(_ perform: @escaping (CGSize) -> Void) -> some View
    • View (iOS 15+)
      • boundsPreference() -> some View
      • onChangeBoundsPreference(_ geometry: GeometryProxy, perform: @escaping (CGSize) -> Void) -> some View
    opened by YusukeHosonuma 0
  • add: `Binding<Value>` -> `Binding<NewValue>`

    add: `Binding` -> `Binding`

    struct BindingMapView: View {
        @State var boolString = "false"
    
        var body: some View {
            VStack {
                TextField("isOn", text: $boolString)
                    .textFieldStyle(.roundedBorder)
                    .autocapitalization(.none)
    
                //
                // 💡 Can edit `String` as `Bool`.
                //
                Toggle("isOn", isOn: $boolString.map( // ✅ `Binding<String>` -> `Binding<Bool>`
                    get: { $0 == "true" },
                    set: { $0 ? "true" : "false" }
                ))
            }
            .padding()
        }
    }
    
    opened by YusukeHosonuma 0
  • add: `Binding<Enum>` -> `Binding<AssociatedValue>?`

    add: `Binding` -> `Binding?`

    struct CaseBindingView: View {
        @State var value: EnumValue = .string("Swift")
    
        var body: some View {
            VStack(alignment: .center) {
                //
                // 💡 Note: `switch` statement is only for completeness check by compiler.
                // (Removal does not affect the operation)
                //
                switch value {
                case .string:
                    //
                    // ✅ Binding<Value> -> Binding<String>?
                    //
                    if let binding = $value.case(/EnumValue.string) {
                        TextField("placeholder", text: binding)
                    }
    
                case .bool:
                    //
                    // ✅ Binding<Value> -> Binding<Int>?
                    //
                    if let binding = $value.case(/EnumValue.bool) {
                        Toggle("isOn", isOn: binding)
                    }
                }
                ...
            }
        }
    }
    
    opened by YusukeHosonuma 0
  • Image+

    Image+

    #if os(macOS)
    private typealias XImage = NSImage
    #else
    private typealias XImage = UIImage
    #endif
    
    struct ImageView: View {
        var body: some View {
            Image(image: renderImage()) // ✅
                .resizable()
                .scaledToFit()
        }
    
        private func renderImage() -> XImage {
            // ⚠️ Assumes rendering code
            #if os(macOS)
            NSImage(named: "picture")!
            #else
            UIImage(named: "picture")!
            #endif
        }
    }
    
    opened by YusukeHosonuma 0
  • Binding+: `wrappedBinding`

    Binding+: `wrappedBinding`

    Usage:

    private struct OptionalTextEditView: View {
        @Binding var optionalString: String? // 💡 `Binding<String?>`
    
        var body: some View {
            //
            // ✅ `Binding<String?>` -> `Binding<String>?`
            //
            if let binding = $optionalString.wrappedBinding() {
                TextField("placeholder", text: binding) // 💡 require `Binding<String>`
                    .textFieldStyle(.roundedBorder)
                    .padding(.horizontal)
            } else {
                Text("nil")
            }
        }
    }
    
    opened by YusukeHosonuma 0
Releases(1.1.0)
Owner
Yusuke Hosonuma
Yusuke Hosonuma
Declarative, configurable & highly reusable UI development as making Lego bricks.

LeeGo is a lightweight Swift framework that helps you decouple & modularise your UI component into small pieces of LEGO style's bricks, to make UI dev

WANG Shengjia 969 Dec 29, 2022
A paging scroll view for SwiftUI, using internal SwiftUI components

PagingView A paging scroll view for SwiftUI, using internal SwiftUI components. This is basically the same as TabView in the paging mode with the inde

Eric Lewis 18 Dec 25, 2022
A custom reusable circular / progress slider control for iOS application.

HGCircularSlider Example To run the example project, clone the repo, and run pod install from the Example directory first. You also may like HGPlaceho

Hamza Ghazouani 2.4k Jan 6, 2023
A few drop-in SwiftUI components for easily importing and thumb-nailing files

FilesUI A few drop-in SwiftUI components for easily importing and thumb-nailing files Usage 1. Import Files To import files you can use the FileImport

Brianna Zamora 3 Oct 19, 2022
SwiftUI: Components Library Inspired by Twitter's Bootstrap

bootswiftui SwiftUI: Components Library Inspired by Twitter's Bootstrap Warning This is just SwiftUI exercise. Please do not consider using this repo

Robert Sandru 1 Oct 27, 2022
Modular and customizable Material Design UI components for iOS

Material Components for iOS Material Components for iOS (MDC-iOS) helps developers execute Material Design. Developed by a core team of engineers and

Material Components 4.6k Dec 29, 2022
NotSwiftUI is designed to help you create UI components quickly and efficiently with code!

NotSwiftUI NotSwiftUI is designed to help you create UI components quickly and efficiently with code! Capitalizing on the idea that most of the UI ele

Jonathan G. 50 Dec 20, 2022
💾 A collection of classic-style UI components for iOS

A collection of classic-style UI components for UIKit, influenced by Windows 95 Introduction This is a little exploration into applying '90s-era desig

Blake Tsuzaki 2.2k Dec 22, 2022
Spinner loader components with liquid animation

LiquidLoader LiquidLoader is the spinner loader UI components with liquid animation, inspired by Spinner Loader - Gooey light Effect [] (https://githu

Takuma Yoshida 1.3k Dec 21, 2022
Material design components for iOS written in Swift

MaterialKit NOTE: This project is unmaintained. Material design components (inspired by Google Material Design) for iOS written in Swift Please feel f

Le Van Nghia 2.5k Jan 5, 2023
Swift Package for distributing Mozilla's Rust-based application components

Swift Package for Mozilla's Rust Components This repository is a Swift Package for distributing releases of Mozilla's various Rust-based application c

Mozilla 19 Dec 30, 2022
It provides UI components such as popover, popup, dialog supporting iOS apps

Overview LCUIComponents is an on-going project, which supports creating transient views appearing above other content onscreen when a control is selec

Linh Chu 7 Apr 8, 2020
Simple and highly customizable iOS tag list view, in Swift.

TagListView Simple and highly customizable iOS tag list view, in Swift. Supports Storyboard, Auto Layout, and @IBDesignable. Usage The most convenient

Ela Workshop 2.5k Jan 5, 2023
A highly configurable and out-of-the-box-pretty UI library

We absolutely love beautiful interfaces! As an organization named Unicorn, we are obligated to be unique and majestic.

Clayton (McIlrath) Unicorn 225 Feb 11, 2022
Highly customizable Action Sheet Controller with Assets Preview written in Swift

PPAssetsActionController Play with me ▶️ ?? If you want to play with me, just tap here and enjoy! ?? ?? Show me ?? Try me ?? The easiest way to try me

Pavel Pantus 72 Feb 4, 2022
📖 A simple, highly informative page view controller

TL;DR UIPageViewController done properly. ⭐️ Features Simplified data source management & enhanced delegation. Dynamically insert & remove pages. Infi

UI At Six 1.8k Dec 24, 2022
Easy to use, highly customizable gauge view

GDGauge - Customizable Gauge View Requirements Xcode 11+ Swift 5 iOS 9+ Installation Swift Package Manager .package(url: "https://github.com/saeid/GDG

Saeid 74 Dec 5, 2022
Swift extensions for UIKit.framework.

XUIKit Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation XUIKit is a

FITZ 0 Oct 22, 2021
xTensions is a collection of useful class extensions for UIKit.

xTensions Intro xTensions is a collection of useful class extensions for UIKit. Swift Package Manager Note: Instructions below are for using SwiftPM w

Alexandre Garrefa 0 Nov 28, 2021