{"id":21913241,"url":"https://github.com/kevinhermawan/viewcondition","last_synced_at":"2025-04-16T06:40:23.594Z","repository":{"id":203118847,"uuid":"708827644","full_name":"kevinhermawan/ViewCondition","owner":"kevinhermawan","description":"An extension to the View protocol that provides conditional view modifiers","archived":false,"fork":false,"pushed_at":"2024-08-12T22:59:17.000Z","size":27,"stargazers_count":10,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-13T21:16:09.275Z","etag":null,"topics":["ios","macos","swifui"],"latest_commit_sha":null,"homepage":"https://kevinhermawan.github.io/ViewCondition/documentation/viewcondition","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinhermawan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-23T13:24:29.000Z","updated_at":"2025-01-26T14:20:03.000Z","dependencies_parsed_at":null,"dependency_job_id":"4969bed6-59b2-4e4b-89ca-003f8c8332d0","html_url":"https://github.com/kevinhermawan/ViewCondition","commit_stats":{"total_commits":12,"total_committers":1,"mean_commits":12.0,"dds":0.0,"last_synced_commit":"a3d0aaf943271247dfd4870a2a0696693165c884"},"previous_names":["kevinhermawan/viewcondition"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2FViewCondition","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2FViewCondition/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2FViewCondition/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinhermawan%2FViewCondition/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinhermawan","download_url":"https://codeload.github.com/kevinhermawan/ViewCondition/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249209267,"owners_count":21230462,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ios","macos","swifui"],"created_at":"2024-11-28T18:15:20.515Z","updated_at":"2025-04-16T06:40:23.554Z","avatar_url":"https://github.com/kevinhermawan.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ViewCondition\n\nAn extension to the `View` protocol that provides conditional view modifiers.\n\n## Overview\n\n`ViewCondition` enhances SwiftUI's conditional rendering capabilities, makes it easier for developers to create adaptive and responsive user interfaces. With `ViewCondition`, you can easily apply modifiers, control visibility, or hide views based on various conditions such as boolean logic, operating system, or module availability. This flexibility allows you to tailor your app's interface for different platforms and user needs without complex conditional statements.\n\n## Documentation\n\nYou can find the documentation here: [https://kevinhermawan.github.io/ViewCondition/documentation/viewcondition](https://kevinhermawan.github.io/ViewCondition/documentation/viewcondition)\n\n## Installation\n\nYou can add `ViewCondition` as a dependency to your project using Swift Package Manager by adding it to the dependencies value of your `Package.swift`.\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/kevinhermawan/ViewCondition.git\", .upToNextMajor(from: \"2.0.0\"))\n]\n```\n\nAlternatively, in Xcode:\n\n1. Open your project in Xcode.\n2. Click on `File` -\u003e `Swift Packages` -\u003e `Add Package Dependency...`\n3. Enter the repository URL: `https://github.com/kevinhermawan/ViewCondition.git`\n4. Choose the version you want to add. You probably want to add the latest version.\n5. Click `Add Package`.\n\n## Usage\n\n### If Modifiers\n\nThe `if` modifiers allow you to conditionally apply modifications to a view.\n\n#### Basic Boolean Condition\n\n```swift\nText(\"Hello, World!\")\n    .if(someCondition) { view in\n        view.foregroundColor(.red)\n    }\n```\n\n#### Operating System Specific\n\n```swift\nText(\"Hello, World!\")\n    .if(os: .iOS) { view in\n        view.padding()\n    }\n```\n\n#### Module Availability\n\n```swift\nText(\"Hello, World!\")\n    .if(canImport: .uiKit) { view in\n        view.foregroundColor(.blue)\n    }\n```\n\n#### Multiple Boolean Conditions\n\n```swift\nText(\"Hello, World!\")\n    .if([condition1, condition2, condition3]) { view in\n        view.bold()\n    }\n```\n\n#### Multiple Operating Systems\n\n```swift\nText(\"Hello, World!\")\n    .if(os: [.iOS, .macOS]) { view in\n        view.font(.largeTitle)\n    }\n```\n\n#### Multiple Module Availabilities\n\n```swift\nText(\"Hello, World!\")\n    .if(canImport: [.uiKit, .appKit]) { view in\n        view.italic()\n    }\n```\n\n### Visible Modifiers\n\nThe `visible` modifiers control the visibility of a view.\n\n#### Basic Boolean Condition\n\n```swift\nText(\"I'm visible!\")\n    .visible(if: someCondition)\n```\n\n#### With Remove Option\n\n```swift\nText(\"I might be removed\")\n    .visible(if: someCondition, removeCompletely: true)\n```\n\n#### Operating System Specific\n\n```swift\nText(\"iOS Only\")\n    .visible(on: .iOS)\n```\n\n#### Module Availability\n\n```swift\nText(\"UIKit Available\")\n    .visible(ifCanImport: .uiKit)\n```\n\n#### Multiple Boolean Conditions\n\n```swift\nText(\"All conditions must be true\")\n    .visible(if: [condition1, condition2, condition3])\n```\n\n#### Multiple Operating Systems\n\n```swift\nText(\"iOS or macOS\")\n    .visible(on: [.iOS, .macOS])\n```\n\n#### Multiple Module Availabilities\n\n```swift\nText(\"UIKit or AppKit\")\n    .visible(ifCanImport: [.uiKit, .appKit])\n```\n\n### Hide Modifiers\n\nThe `hide` modifiers control the hiding of a view.\n\n#### Basic Boolean Condition\n\n```swift\nText(\"I'm hidden!\")\n    .hide(if: someCondition)\n```\n\n#### With Remove Option\n\n```swift\nText(\"I might be removed\")\n    .hide(if: someCondition, removeCompletely: true)\n```\n\n#### Operating System Specific\n\n```swift\nText(\"Hidden on iOS\")\n    .hide(on: .iOS)\n```\n\n#### Module Availability\n\n```swift\nText(\"Hidden if UIKit is available\")\n    .hide(ifCanImport: .uiKit)\n```\n\n#### Multiple Boolean Conditions\n\n```swift\nText(\"Hidden if all conditions are true\")\n    .hide(if: [condition1, condition2, condition3])\n```\n\n#### Multiple Operating Systems\n\n```swift\nText(\"Hidden on iOS or macOS\")\n    .hide(on: [.iOS, .macOS])\n```\n\n#### Multiple Module Availabilities\n\n```swift\nText(\"Hidden if UIKit or AppKit is available\")\n    .hide(ifCanImport: [.uiKit, .appKit])\n```\n\n## License\n\n[MIT License](/LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhermawan%2Fviewcondition","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinhermawan%2Fviewcondition","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinhermawan%2Fviewcondition/lists"}