-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from orchidfire/master
Tweaks from cursor.so
- Loading branch information
Showing
12 changed files
with
194 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,32 @@ | ||
#if os(iOS) | ||
import UIKit | ||
#endif | ||
|
||
extension UIApplication { | ||
/** | ||
* Overrides the user interface style adopted by all windows in all connected scenes. | ||
* - Parameter userInterfaceStyle: The user interface style adopted by all windows in all connected scenes. | ||
* ## Examples: | ||
* let mode: UIUserInterfaceStyle = self.isDarkMode ? .light : .dark | ||
* UIApplication.shared.override(mode) | ||
*/ | ||
public func override(_ userInterfaceStyle: UIUserInterfaceStyle) { | ||
if #available(iOS 13.0, *), supportsMultipleScenes { | ||
connectedScenes.forEach { connectedScene in | ||
if let scene = connectedScene as? UIWindowScene { | ||
scene.windows.override(userInterfaceStyle) | ||
/** | ||
* This function allows you to override the user interface style for all windows in all connected scenes. | ||
* This can be useful for implementing features like a 'Dark Mode' toggle. | ||
* | ||
* - Parameter userInterfaceStyle: The desired user interface style. This can be either .light or .dark. | ||
* | ||
* ## Usage Example: | ||
* Determine the current mode, then switch to the opposite mode: | ||
* ``` | ||
* let currentMode: UIUserInterfaceStyle = self.isDarkMode ? .light : .dark | ||
* UIApplication.shared.override(currentMode) | ||
* ``` | ||
*/ | ||
public func override(_ userInterfaceStyle: UIUserInterfaceStyle) { | ||
if #available(iOS 13.0, *), supportsMultipleScenes { | ||
connectedScenes.forEach { connectedScene in | ||
// Check if the connected scene is a UIWindowScene, then override its style | ||
if let scene = connectedScene as? UIWindowScene { | ||
scene.windows.override(userInterfaceStyle) | ||
} | ||
} | ||
} | ||
} else { | ||
windows.override(userInterfaceStyle) | ||
} | ||
} | ||
} | ||
#endif | ||
} else { | ||
// If the iOS version is less than 13.0 or does not support multiple scenes, override the style for all windows | ||
windows.override(userInterfaceStyle) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,48 +1,56 @@ | ||
#if os(iOS) | ||
import UIKit | ||
|
||
/** | ||
* ## Examples: | ||
* let imageAsset = UIImageAsset(lightModeImage: .init(named: "lightLogo"), darkModeImage: .init(named: "darkLogo")) | ||
* This UIImageAsset extension provides convenience methods for registering and retrieving images based on user interface style. | ||
* It simplifies the process of managing different images for light and dark modes. | ||
* | ||
* ## Usage: | ||
* let imageAsset = UIImageAsset(lightModeImage: UIImage(named: "lightLogo"), darkModeImage: UIImage(named: "darkLogo")) | ||
*/ | ||
extension UIImageAsset { | ||
/** | ||
* Creates an image asset with registration of tht eimages with the light and dark trait collections. | ||
* Convenience initializer for creating an image asset and registering images for light and dark user interface styles. | ||
* - Parameters: | ||
* - lightModeImage: The image you want to register with the image asset with light user interface style. | ||
* - darkModeImage: The image you want to register with the image asset with dark user interface style. | ||
* - lightModeImage: The image to be used in light user interface style. | ||
* - darkModeImage: The image to be used in dark user interface style. | ||
*/ | ||
public convenience init(lightModeImage: UIImage?, darkModeImage: UIImage?) { | ||
self.init() | ||
register(lightModeImage: lightModeImage, darkModeImage: darkModeImage) | ||
} | ||
|
||
/** | ||
* Register an images with the light and dark trait collections respectively. | ||
*- Parameters: | ||
* - lightModeImage: The image you want to register with the image asset with light user interface style. | ||
* - darkModeImage: The image you want to register with the image asset with dark user interface style. | ||
* Method to register images for light and dark user interface styles. | ||
* - Parameters: | ||
* - lightModeImage: The image to be used in light user interface style. | ||
* - darkModeImage: The image to be used in dark user interface style. | ||
*/ | ||
public func register(lightModeImage: UIImage?, darkModeImage: UIImage?) { | ||
register(lightModeImage, for: .light) | ||
register(darkModeImage, for: .dark) | ||
} | ||
|
||
/** | ||
* Register an image with the specified trait collection. | ||
* Method to register an image for a specific user interface style. | ||
* - Parameters: | ||
* - image: The image you want to register with the image asset. | ||
* - traitCollection: The traits to associate with image. | ||
* - image: The image to be registered with the image asset. | ||
* - traitCollection: The user interface style to associate with the image. | ||
*/ | ||
public func register(_ image: UIImage?, for userInterfaceStyle: UIUserInterfaceStyle) { | ||
guard let image = image else { return } | ||
register(image, with: .init(userInterfaceStyle: userInterfaceStyle)) | ||
register(image, with: UITraitCollection(userInterfaceStyle: userInterfaceStyle)) | ||
} | ||
|
||
/** | ||
* Returns the variant of the image that best matches the current trait collection. For early SDKs returns the image for light user interface style. | ||
* Method to retrieve the image variant that best matches the current trait collection. | ||
* For early SDKs, it returns the image for light user interface style. | ||
*/ | ||
public func image() -> UIImage { | ||
if #available(iOS 13.0, tvOS 13.0, *) { | ||
image(with: .current) | ||
return image(with: UITraitCollection.current) | ||
} | ||
return image(with: .init(userInterfaceStyle: .light)) | ||
return image(with: UITraitCollection(userInterfaceStyle: .light)) | ||
} | ||
} | ||
#endif | ||
#endif | ||
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
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 |
---|---|---|
@@ -1,16 +1,22 @@ | ||
#if os(iOS) | ||
import UIKit | ||
#endif | ||
|
||
extension UserDefaults { | ||
/** | ||
* Save overriden user interface style | ||
* This computed property allows you to save and retrieve the user's preferred UI style. | ||
* It uses the UserDefaults system to persist this preference across app launches. | ||
* If no preference has been set, it defaults to 'unspecified'. | ||
*/ | ||
public var overridedUserInterfaceStyle: UIUserInterfaceStyle { | ||
get { | ||
// Fetch the raw value of the UI style from UserDefaults using the function name as the key. | ||
// If no value is found, default to 'unspecified'. | ||
UIUserInterfaceStyle(rawValue: integer(forKey: #function)) ?? .unspecified | ||
} set { | ||
} | ||
set { | ||
// Save the raw value of the new UI style to UserDefaults using the function name as the key. | ||
set(newValue.rawValue, forKey: #function) | ||
} | ||
} | ||
} | ||
#endif | ||
} | ||
Oops, something went wrong.