forked from microsoft/fluentui-apple
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning up warnings in Demo app (microsoft#1979)
- Loading branch information
1 parent
7a1bc97
commit 1ec3c51
Showing
4 changed files
with
40 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
ios/FluentUI.Demo/FluentUI.Demo/SwiftUI/View+Extensions.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension View { | ||
/// Abstracts away differences in pre-iOS 17 `onChange(of:perform:)` versus post-iOS 17 `onChange(of:_:)`. | ||
/// | ||
/// This function will be removed once FluentUI moves to iOS 17 as a minimum target. | ||
/// - Parameters: | ||
/// - value: The value to check against when determining whether to run the closure. | ||
/// - action: A closure to run when the value changes. | ||
/// - Returns: A view that fires an action when the specified value changes. | ||
func onChange_iOS17<V>(of value: V, _ action: @escaping (V) -> Void) -> some View where V: Equatable { | ||
if #available(iOS 17, *) { | ||
return self.onChange(of: value) { _, newValue in | ||
return action(newValue) | ||
} | ||
} else { | ||
return self.onChange(of: value, perform: action) | ||
} | ||
} | ||
} |