✨ Super sweet syntactic sugar for SwiftUI.View initializers.

Related tags

Layout ViewCondition
Overview

ViewCondition

Super sweet syntactic sugar for SwiftUI.View initializers.

At a Glance

struct BorderTextView: View {
  var color: Color?

  @ViewBuilder
  var body: some View {
    Text("Hello")
      .if(let: color) {
        $0.border($1)
      }
  }
}

This is equivalent to:

struct BorderTextView: View {
  var color: Color?

  @ViewBuilder
  var body: some View {
    let text = Text("Hello")
    if let color = color {
      text.border(color) // border doesn't allow optional
    } else {
      text
    }
  }
}

Operators

if let

let color: Color?
Text("Hello")
  .if(let: color) {
    $0.border($1)
  }

if

let text = ""
Text("Hello")
  .if(text == "Hello") {
    $0.bold()
  }

ifNot

let text = ""
Text("Hello")
  .ifNot(text == "Hello") {
    $0.bold()
  }

then

let text = ""
Text("Hello")
  .then {
    if text == "Hello" {
      $0.bold()
    } else {
      $0.italic()
    }
  }

⚠️ Becareful

If you don't return view in else, the view may not come out.

Installation

Using Swift Package Manager:

import PackageDescription

let package = Package(
  name: "MyAwesomeApp",
  dependencies: [
    .package(url: "https://github.com/tokijh/ViewCondition.git", from: "1.0.0")
  ]
)

Special thanks to..

License

ViewCondition is under MIT license. See the LICENSE file for more info.

You might also like...
ReadabilityModifier - UIKits readableContentGuide for every SwiftUI View, in the form of a ViewModifier
ReadabilityModifier - UIKits readableContentGuide for every SwiftUI View, in the form of a ViewModifier

ReadabilityModifier UIKits readableContentGuide for every SwiftUI View, in the form of a ViewModifier What it is Displaying multiple lines of text in

A SwiftUI proof-of-concept, and some sleight-of-hand, which adds rain to a view's background
A SwiftUI proof-of-concept, and some sleight-of-hand, which adds rain to a view's background

Atmos A SwiftUI proof-of-concept, and some sleight-of-hand, which adds rain to a view's background. "Ima use this in my app..." Introducing Metal to S

A SwiftUI ScrollView that runs a callback when subviews are scrolled in and out of view.

VisibilityTrackingScrollView This package provides a variant of ScrollView that you can use to track whether views inside it are actually visible. Usa

What's New In SwiftUI for iOS 16 - Xcode 14 -  SwiftUI 4.0
What's New In SwiftUI for iOS 16 - Xcode 14 - SwiftUI 4.0

SwiftUI4 What's New In SwiftUI for iOS 16 - Xcode 14 - SwiftUI 4.0 (Work in progress....) Swift Charts Presentation Detents(Half Sheet & Small Sheets)

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
LayoutKit is a fast view layout library for iOS, macOS, and tvOS.

🚨 UNMAINTAINED 🚨 This project is no longer used by LinkedIn and is currently unmaintained. LayoutKit is a fast view layout library for iOS, macOS, a

iOS simple project to create half-screen modal view controller with pan
iOS simple project to create half-screen modal view controller with pan

Simple Half-screen view controller, draggable and less code (learning purpose)

Programmatic view layout for the rest of us.
Programmatic view layout for the rest of us.

Façade Important Facade is no longer under active development, and as such if you create any issues or submit pull requests, it's not very likely to b

LayoutKit is a fast view layout library for iOS, macOS, and tvOS.
LayoutKit is a fast view layout library for iOS, macOS, and tvOS.

🚨 UNMAINTAINED 🚨 This project is no longer used by LinkedIn and is currently unmaintained. LayoutKit is a fast view layout library for iOS, macOS, a

MyLayout is a simple and easy objective-c framework for iOS view layout
MyLayout is a simple and easy objective-c framework for iOS view layout

MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITableView UICollectionView RTL

Releases(1.0.0)
Owner
Yoon Joonghyun
Hi, I am a developer in Korea 🙌
Yoon Joonghyun
Declarative iOS UI sugar framework built on FlexLayout

Declarative iOS UI sugar framework built on FlexLayout

당근마켓 97 Dec 9, 2022
FrameLayoutKit is a super fast and easy to use autolayout kit

FrameLayoutKit FrameLayout is a super fast and easy to use layout library for iOS and tvOS. For Objective-C version: NKFrameLayoutKit (Deprecated, not

Nam Kennic 57 Jun 24, 2022
Super-senha-app - Application made from Eric Brito's Udemy course

super-senha-app Aplicativo feito a partir do curso do Eric Brito da Udemy

Michelli Cristina de Paulo Lima 0 Feb 11, 2022
Modern-collection-view - Modern collection view for swift

Modern collection view Sample application demonstrating the use of collection vi

Nitanta Adhikari 1 Jan 24, 2022
Flow layout / tag cloud / collection view in SwiftUI.

SwiftUIFlowLayout A Flow Layout is a container that orders its views sequentially, breaking into a new "line" according to the available width of the

Gordan Glavaš 115 Dec 28, 2022
NStack is a SwiftUI view that allows you to hoist navigation state into a Coordinator

An NStack allows you to manage SwiftUI navigation state with a single stack property. This makes it easy to hoist that state into a high-level view, such as a coordinator. The coordinator pattern allows you to write isolated views that have zero knowledge of their context within the navigation flow of an app.

John Patrick Morgan 469 Dec 27, 2022
Half modal view for SwiftUI

ResizableSheet ResizableSheeet is a half modal view library for SwiftUI. You can easily implement a half modal view. Target Swift5.5 iOS14+ Installati

matsuji 76 Dec 16, 2022
SwiftUI package to present a Bottom Sheet interactable view with the desired Detents. Also known as Half sheet.

BottomSheetSUI BottomSheetSUI is a package that gives you the ability to show a Bottom sheet intractable, where you can add your own SwiftUI view. You

Aitor Pagán 8 Nov 28, 2022
A grid layout view for SwiftUI

Update July 2020 - latest SwiftUI now has built-in components to do this, which should be used instead. FlowStack FlowStack is a SwiftUI component for

John Susek 147 Nov 10, 2022
Horizontal and Vertical collection view for infinite scrolling that was designed to be used in SwiftUI

InfiniteScroller Example struct ContentView: View { @State var selected: Int = 1 var body: some View { InfiniteScroller(direction: .ve

Serhii Reznichenko 5 Apr 17, 2022