@sbaiahmed1/react-native-blur 3.0.0-beta.1 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +209 -107
- package/ReactNativeBlur.podspec +1 -0
- package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeBlurViewManagerDelegate.java +18 -3
- package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeBlurViewManagerInterface.java +6 -1
- package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeGlassEffectContainerManagerDelegate.java +53 -0
- package/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/ReactNativeGlassEffectContainerManagerInterface.java +25 -0
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ComponentDescriptors.cpp +1 -1
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ComponentDescriptors.h +1 -1
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/EventEmitters.h +1 -1
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/Props.cpp +17 -7
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/Props.h +55 -15
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ShadowNodes.cpp +1 -1
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/ShadowNodes.h +7 -7
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/ReactNativeBlurViewSpec/States.h +3 -3
- package/ios/Helpers/BlurStyleHelpers.swift +59 -0
- package/ios/Helpers/ReactNativeBlurViewHelper.swift +59 -0
- package/ios/ReactNativeBlurView.mm +6 -1
- package/ios/ReactNativeBlurViewManager.m +6 -0
- package/ios/Views/AdvancedBlurView.swift +94 -0
- package/ios/Views/BasicColoredView.swift +58 -0
- package/ios/Views/BlurEffectView.swift +70 -0
- package/package.json +1 -1
- package/ios/ReactNativeBlurView.swift +0 -321
|
@@ -14,6 +14,21 @@
|
|
|
14
14
|
|
|
15
15
|
namespace facebook::react {
|
|
16
16
|
|
|
17
|
+
enum class ReactNativeBlurViewType { Blur, LiquidGlass };
|
|
18
|
+
|
|
19
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ReactNativeBlurViewType &result) {
|
|
20
|
+
auto string = (std::string)value;
|
|
21
|
+
if (string == "blur") { result = ReactNativeBlurViewType::Blur; return; }
|
|
22
|
+
if (string == "liquidGlass") { result = ReactNativeBlurViewType::LiquidGlass; return; }
|
|
23
|
+
abort();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static inline std::string toString(const ReactNativeBlurViewType &value) {
|
|
27
|
+
switch (value) {
|
|
28
|
+
case ReactNativeBlurViewType::Blur: return "blur";
|
|
29
|
+
case ReactNativeBlurViewType::LiquidGlass: return "liquidGlass";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
17
32
|
enum class ReactNativeBlurViewBlurType { Xlight, Light, Dark, ExtraDark, Regular, Prominent, SystemUltraThinMaterial, SystemThinMaterial, SystemMaterial, SystemThickMaterial, SystemChromeMaterial };
|
|
18
33
|
|
|
19
34
|
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ReactNativeBlurViewBlurType &result) {
|
|
@@ -47,6 +62,21 @@ static inline std::string toString(const ReactNativeBlurViewBlurType &value) {
|
|
|
47
62
|
case ReactNativeBlurViewBlurType::SystemChromeMaterial: return "systemChromeMaterial";
|
|
48
63
|
}
|
|
49
64
|
}
|
|
65
|
+
enum class ReactNativeBlurViewGlassType { Clear, Regular };
|
|
66
|
+
|
|
67
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ReactNativeBlurViewGlassType &result) {
|
|
68
|
+
auto string = (std::string)value;
|
|
69
|
+
if (string == "clear") { result = ReactNativeBlurViewGlassType::Clear; return; }
|
|
70
|
+
if (string == "regular") { result = ReactNativeBlurViewGlassType::Regular; return; }
|
|
71
|
+
abort();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static inline std::string toString(const ReactNativeBlurViewGlassType &value) {
|
|
75
|
+
switch (value) {
|
|
76
|
+
case ReactNativeBlurViewGlassType::Clear: return "clear";
|
|
77
|
+
case ReactNativeBlurViewGlassType::Regular: return "regular";
|
|
78
|
+
}
|
|
79
|
+
}
|
|
50
80
|
|
|
51
81
|
class ReactNativeBlurViewProps final : public ViewProps {
|
|
52
82
|
public:
|
|
@@ -55,37 +85,47 @@ class ReactNativeBlurViewProps final : public ViewProps {
|
|
|
55
85
|
|
|
56
86
|
#pragma mark - Props
|
|
57
87
|
|
|
58
|
-
|
|
88
|
+
std::string glassTintColor{"clear"};
|
|
89
|
+
double glassOpacity{1.0};
|
|
59
90
|
double blurAmount{10.0};
|
|
60
|
-
|
|
91
|
+
ReactNativeBlurViewType type{ReactNativeBlurViewType::Blur};
|
|
92
|
+
ReactNativeBlurViewBlurType blurType{ReactNativeBlurViewBlurType::Xlight};
|
|
93
|
+
ReactNativeBlurViewGlassType glassType{ReactNativeBlurViewGlassType::Clear};
|
|
94
|
+
std::string reducedTransparencyFallbackColor{"#FFFFFF"};
|
|
95
|
+
bool isInteractive{true};
|
|
61
96
|
};
|
|
62
97
|
|
|
63
|
-
enum class
|
|
98
|
+
enum class ReactNativeGlassEffectContainerGlassType { Clear, Regular };
|
|
64
99
|
|
|
65
|
-
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value,
|
|
100
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, ReactNativeGlassEffectContainerGlassType &result) {
|
|
66
101
|
auto string = (std::string)value;
|
|
67
|
-
if (string == "clear") { result =
|
|
68
|
-
if (string == "
|
|
102
|
+
if (string == "clear") { result = ReactNativeGlassEffectContainerGlassType::Clear; return; }
|
|
103
|
+
if (string == "regular") { result = ReactNativeGlassEffectContainerGlassType::Regular; return; }
|
|
69
104
|
abort();
|
|
70
105
|
}
|
|
71
106
|
|
|
72
|
-
static inline std::string toString(const
|
|
107
|
+
static inline std::string toString(const ReactNativeGlassEffectContainerGlassType &value) {
|
|
73
108
|
switch (value) {
|
|
74
|
-
case
|
|
75
|
-
case
|
|
109
|
+
case ReactNativeGlassEffectContainerGlassType::Clear: return "clear";
|
|
110
|
+
case ReactNativeGlassEffectContainerGlassType::Regular: return "regular";
|
|
76
111
|
}
|
|
77
112
|
}
|
|
78
113
|
|
|
79
|
-
class
|
|
114
|
+
class ReactNativeGlassEffectContainerProps final : public ViewProps {
|
|
80
115
|
public:
|
|
81
|
-
|
|
82
|
-
|
|
116
|
+
ReactNativeGlassEffectContainerProps() = default;
|
|
117
|
+
ReactNativeGlassEffectContainerProps(const PropsParserContext& context, const ReactNativeGlassEffectContainerProps &sourceProps, const RawProps &rawProps);
|
|
83
118
|
|
|
84
119
|
#pragma mark - Props
|
|
85
120
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
121
|
+
ReactNativeGlassEffectContainerGlassType glassType{ReactNativeGlassEffectContainerGlassType::Clear};
|
|
122
|
+
std::string glassTintColor{"clear"};
|
|
123
|
+
double glassOpacity{1.0};
|
|
124
|
+
bool isInteractive{true};
|
|
125
|
+
double spacing{8.0};
|
|
126
|
+
bool enableMorphing{true};
|
|
127
|
+
int morphingDuration{300};
|
|
128
|
+
std::string reducedTransparencyFallbackColor{"#FFFFFF"};
|
|
89
129
|
};
|
|
90
130
|
|
|
91
131
|
} // namespace facebook::react
|
|
@@ -13,6 +13,6 @@
|
|
|
13
13
|
namespace facebook::react {
|
|
14
14
|
|
|
15
15
|
extern const char ReactNativeBlurViewComponentName[] = "ReactNativeBlurView";
|
|
16
|
-
extern const char
|
|
16
|
+
extern const char ReactNativeGlassEffectContainerComponentName[] = "ReactNativeGlassEffectContainer";
|
|
17
17
|
|
|
18
18
|
} // namespace facebook::react
|
|
@@ -29,15 +29,15 @@ using ReactNativeBlurViewShadowNode = ConcreteViewShadowNode<
|
|
|
29
29
|
ReactNativeBlurViewEventEmitter,
|
|
30
30
|
ReactNativeBlurViewState>;
|
|
31
31
|
|
|
32
|
-
JSI_EXPORT extern const char
|
|
32
|
+
JSI_EXPORT extern const char ReactNativeGlassEffectContainerComponentName[];
|
|
33
33
|
|
|
34
34
|
/*
|
|
35
|
-
* `ShadowNode` for <
|
|
35
|
+
* `ShadowNode` for <ReactNativeGlassEffectContainer> component.
|
|
36
36
|
*/
|
|
37
|
-
using
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
using ReactNativeGlassEffectContainerShadowNode = ConcreteViewShadowNode<
|
|
38
|
+
ReactNativeGlassEffectContainerComponentName,
|
|
39
|
+
ReactNativeGlassEffectContainerProps,
|
|
40
|
+
ReactNativeGlassEffectContainerEventEmitter,
|
|
41
|
+
ReactNativeGlassEffectContainerState>;
|
|
42
42
|
|
|
43
43
|
} // namespace facebook::react
|
|
@@ -26,12 +26,12 @@ public:
|
|
|
26
26
|
#endif
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
class
|
|
29
|
+
class ReactNativeGlassEffectContainerState {
|
|
30
30
|
public:
|
|
31
|
-
|
|
31
|
+
ReactNativeGlassEffectContainerState() = default;
|
|
32
32
|
|
|
33
33
|
#ifdef ANDROID
|
|
34
|
-
|
|
34
|
+
ReactNativeGlassEffectContainerState(ReactNativeGlassEffectContainerState const &previousState, folly::dynamic data){};
|
|
35
35
|
folly::dynamic getDynamic() const {
|
|
36
36
|
return {};
|
|
37
37
|
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// BlurStyleHelpers.swift
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
// MARK: - Style Mapping Helper Functions
|
|
7
|
+
|
|
8
|
+
/// Maps string blur style names to UIBlurEffect.Style values
|
|
9
|
+
func blurStyleFromString(_ styleString: String) -> UIBlurEffect.Style {
|
|
10
|
+
switch styleString {
|
|
11
|
+
case "xlight":
|
|
12
|
+
return .extraLight
|
|
13
|
+
case "light":
|
|
14
|
+
return .light
|
|
15
|
+
case "dark":
|
|
16
|
+
return .dark
|
|
17
|
+
case "extraDark":
|
|
18
|
+
return .systemThickMaterialDark
|
|
19
|
+
case "regular":
|
|
20
|
+
return .regular
|
|
21
|
+
case "prominent":
|
|
22
|
+
return .prominent
|
|
23
|
+
case "systemUltraThinMaterial":
|
|
24
|
+
return .systemUltraThinMaterial
|
|
25
|
+
case "systemThinMaterial":
|
|
26
|
+
return .systemThinMaterial
|
|
27
|
+
case "systemMaterial":
|
|
28
|
+
return .systemMaterial
|
|
29
|
+
case "systemThickMaterial":
|
|
30
|
+
return .systemThickMaterial
|
|
31
|
+
case "systemChromeMaterial":
|
|
32
|
+
return .systemChromeMaterial
|
|
33
|
+
default:
|
|
34
|
+
return .extraLight
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// Maps string glass type names to Glass effect values (iOS 26.0+)
|
|
39
|
+
@available(iOS 26.0, *)
|
|
40
|
+
func glassEffectFromString(_ glassTypeString: String) -> Glass {
|
|
41
|
+
switch glassTypeString {
|
|
42
|
+
case "regular":
|
|
43
|
+
return .regular
|
|
44
|
+
case "clear":
|
|
45
|
+
return .clear
|
|
46
|
+
default:
|
|
47
|
+
return .clear
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// MARK: - Blur Amount Mapping
|
|
52
|
+
|
|
53
|
+
/// Maps blur amount (0-100) to proper blur intensity using UIViewPropertyAnimator approach
|
|
54
|
+
func mapBlurAmountToIntensity(_ amount: Double) -> Double {
|
|
55
|
+
let clampedAmount = max(0.0, min(100.0, amount))
|
|
56
|
+
|
|
57
|
+
// Map 0-100 to 0-1.0 intensity for smooth progression
|
|
58
|
+
return clampedAmount / 100.0
|
|
59
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// ReactNativeBlurViewHelper.swift
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
// MARK: - Objective-C Bridging Helpers
|
|
7
|
+
|
|
8
|
+
@objc public class ReactNativeBlurViewHelper: NSObject {
|
|
9
|
+
|
|
10
|
+
/// Creates and returns a view containing a colored rectangle.
|
|
11
|
+
@objc public static func createBlurViewWithFrame(_ frame: CGRect) -> AdvancedBlurView {
|
|
12
|
+
return AdvancedBlurView(frame: frame)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/// Updates the blur view with a new glass tint color.
|
|
16
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withGlassTintColor glassTintColor: UIColor) {
|
|
17
|
+
blurView.glassTintColor = glassTintColor
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/// Updates the blur view with a new glass opacity.
|
|
21
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withGlassOpacity glassOpacity: Double) {
|
|
22
|
+
blurView.glassOpacity = glassOpacity
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Updates the blur view with a new blur amount.
|
|
26
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withBlurAmount blurAmount: Double) {
|
|
27
|
+
blurView.blurAmount = blurAmount
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/// Updates the blur view with a new blur type.
|
|
31
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withBlurType blurType: String) {
|
|
32
|
+
blurView.blurTypeString = blurType
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/// Updates the blur view with a new glass type.
|
|
36
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withGlassType glassType: String) {
|
|
37
|
+
blurView.glassType = glassType
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// Updates the blur view with a new blur style.
|
|
41
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withType type: String) {
|
|
42
|
+
blurView.type = type
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Updates the blur view with a new blur style.
|
|
46
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withIsInteractive isInteractive: Bool) {
|
|
47
|
+
blurView.isInteractive = isInteractive
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/// Updates the blur view with a new reduced transparency fallback color.
|
|
51
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView, withReducedTransparencyFallbackColor fallbackColor: UIColor) {
|
|
52
|
+
blurView.reducedTransparencyFallbackColor = fallbackColor
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// No-op updater kept for API compatibility.
|
|
56
|
+
@objc public static func updateBlurView(_ blurView: AdvancedBlurView) {
|
|
57
|
+
// Nothing to update in the minimal implementation
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -6,7 +6,12 @@
|
|
|
6
6
|
#import <react/renderer/components/ReactNativeBlurViewSpec/RCTComponentViewHelpers.h>
|
|
7
7
|
|
|
8
8
|
#import "RCTFabricComponentsPlugins.h"
|
|
9
|
-
|
|
9
|
+
|
|
10
|
+
#if __has_include("ReactNativeBlur-Swift.h")
|
|
11
|
+
#import "ReactNativeBlur-Swift.h"
|
|
12
|
+
#else
|
|
13
|
+
#import <ReactNativeBlur/ReactNativeBlur-Swift.h>
|
|
14
|
+
#endif
|
|
10
15
|
|
|
11
16
|
using namespace facebook::react;
|
|
12
17
|
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
#import "ReactNativeBlurViewManager.h"
|
|
2
|
+
|
|
3
|
+
#if __has_include("ReactNativeBlur-Swift.h")
|
|
2
4
|
#import "ReactNativeBlur-Swift.h"
|
|
5
|
+
#else
|
|
6
|
+
#import <ReactNativeBlur/ReactNativeBlur-Swift.h>
|
|
7
|
+
#endif
|
|
8
|
+
|
|
3
9
|
#import <React/RCTUIManager.h>
|
|
4
10
|
#import <React/RCTBridge.h>
|
|
5
11
|
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// AdvancedBlurView.swift
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
// MARK: - UIKit Wrapper
|
|
7
|
+
|
|
8
|
+
@objc public class AdvancedBlurView: UIView {
|
|
9
|
+
|
|
10
|
+
private var hostingController: UIHostingController<BasicColoredView>?
|
|
11
|
+
|
|
12
|
+
@objc public var glassTintColor: UIColor = .clear {
|
|
13
|
+
didSet {
|
|
14
|
+
updateView()
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
@objc public var glassOpacity: Double = 1.0 {
|
|
19
|
+
didSet {
|
|
20
|
+
updateView()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
@objc public var blurAmount: Double = 10.0 {
|
|
25
|
+
didSet {
|
|
26
|
+
updateView()
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
@objc public var type: String = "blur" {
|
|
31
|
+
didSet {
|
|
32
|
+
updateView()
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@objc public var blurTypeString: String = "xlight" {
|
|
37
|
+
didSet {
|
|
38
|
+
updateView()
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
@objc public var glassType: String = "clear" {
|
|
43
|
+
didSet {
|
|
44
|
+
updateView()
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@objc public var reducedTransparencyFallbackColor: UIColor = .white {
|
|
49
|
+
didSet {
|
|
50
|
+
updateView()
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@objc public var isInteractive: Bool = true {
|
|
55
|
+
didSet {
|
|
56
|
+
updateView()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public override init(frame: CGRect) {
|
|
61
|
+
super.init(frame: frame)
|
|
62
|
+
setupHostingController()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
required init?(coder: NSCoder) {
|
|
66
|
+
super.init(coder: coder)
|
|
67
|
+
setupHostingController()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private func setupHostingController() {
|
|
71
|
+
let blurStyle = blurStyleFromString(blurTypeString)
|
|
72
|
+
let swiftUIView = BasicColoredView(glassTintColor: glassTintColor, glassOpacity: glassOpacity, blurAmount: blurAmount, blurStyle: blurStyle, type: type, glassType: glassType, reducedTransparencyFallbackColor: reducedTransparencyFallbackColor, isInteractive: isInteractive)
|
|
73
|
+
let hosting = UIHostingController(rootView: swiftUIView)
|
|
74
|
+
|
|
75
|
+
hosting.view.backgroundColor = .clear
|
|
76
|
+
hosting.view.translatesAutoresizingMaskIntoConstraints = false
|
|
77
|
+
|
|
78
|
+
addSubview(hosting.view)
|
|
79
|
+
NSLayoutConstraint.activate([
|
|
80
|
+
hosting.view.topAnchor.constraint(equalTo: topAnchor),
|
|
81
|
+
hosting.view.leadingAnchor.constraint(equalTo: leadingAnchor),
|
|
82
|
+
hosting.view.trailingAnchor.constraint(equalTo: trailingAnchor),
|
|
83
|
+
hosting.view.bottomAnchor.constraint(equalTo: bottomAnchor)
|
|
84
|
+
])
|
|
85
|
+
|
|
86
|
+
self.hostingController = hosting
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
private func updateView() {
|
|
90
|
+
let blurStyle = blurStyleFromString(blurTypeString)
|
|
91
|
+
let newSwiftUIView = BasicColoredView(glassTintColor: glassTintColor, glassOpacity: glassOpacity, blurAmount: blurAmount, blurStyle: blurStyle, type:type, glassType: glassType, reducedTransparencyFallbackColor: reducedTransparencyFallbackColor, isInteractive: isInteractive)
|
|
92
|
+
hostingController?.rootView = newSwiftUIView
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// BasicColoredView.swift
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
// MARK: - SwiftUI View Component
|
|
7
|
+
|
|
8
|
+
struct BasicColoredView: View {
|
|
9
|
+
var glassTintColor: UIColor
|
|
10
|
+
var glassOpacity: Double
|
|
11
|
+
var blurAmount: Double
|
|
12
|
+
var blurStyle: UIBlurEffect.Style
|
|
13
|
+
var type: String
|
|
14
|
+
var glassType: String
|
|
15
|
+
var reducedTransparencyFallbackColor: UIColor
|
|
16
|
+
var isInteractive: Bool
|
|
17
|
+
|
|
18
|
+
var body: some View {
|
|
19
|
+
let blurIntensity = mapBlurAmountToIntensity(blurAmount)
|
|
20
|
+
|
|
21
|
+
// Check if reduced transparency is enabled
|
|
22
|
+
let isReducedTransparencyEnabled = UIAccessibility.isReduceTransparencyEnabled
|
|
23
|
+
|
|
24
|
+
if isReducedTransparencyEnabled {
|
|
25
|
+
// Use fallback color when reduced transparency is enabled
|
|
26
|
+
Rectangle()
|
|
27
|
+
.fill(Color(reducedTransparencyFallbackColor))
|
|
28
|
+
} else {
|
|
29
|
+
if (type == "liquidGlass"){
|
|
30
|
+
if #available(iOS 26.0, *) {
|
|
31
|
+
let baseGlassEffect = glassEffectFromString(glassType)
|
|
32
|
+
Rectangle()
|
|
33
|
+
.glassEffect(
|
|
34
|
+
baseGlassEffect
|
|
35
|
+
.tint(Color(glassTintColor)
|
|
36
|
+
.opacity(glassOpacity))
|
|
37
|
+
.interactive(isInteractive)
|
|
38
|
+
, in: .rect)
|
|
39
|
+
|
|
40
|
+
} else {
|
|
41
|
+
// Use proper blur intensity control for liquid glass fallback
|
|
42
|
+
Rectangle()
|
|
43
|
+
.fill(Color(.clear))
|
|
44
|
+
.background(Blur(style: blurStyle, intensity: blurIntensity))
|
|
45
|
+
.overlay(
|
|
46
|
+
Color(glassTintColor)
|
|
47
|
+
.opacity(glassOpacity)
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
}else {
|
|
51
|
+
// Use proper blur intensity control for regular blur
|
|
52
|
+
Rectangle()
|
|
53
|
+
.fill(Color(.clear))
|
|
54
|
+
.background(Blur(style: blurStyle, intensity: blurIntensity))
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// BlurEffectView.swift
|
|
2
|
+
|
|
3
|
+
import SwiftUI
|
|
4
|
+
import UIKit
|
|
5
|
+
|
|
6
|
+
// MARK: - Blur View with proper intensity control
|
|
7
|
+
|
|
8
|
+
class BlurEffectView: UIVisualEffectView {
|
|
9
|
+
private var animator: UIViewPropertyAnimator?
|
|
10
|
+
private var blurStyle: UIBlurEffect.Style = .systemMaterial
|
|
11
|
+
private var intensity: Double = 1.0
|
|
12
|
+
|
|
13
|
+
override init(effect: UIVisualEffect?) {
|
|
14
|
+
super.init(effect: effect)
|
|
15
|
+
setupBlur()
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
required init?(coder: NSCoder) {
|
|
19
|
+
super.init(coder: coder)
|
|
20
|
+
setupBlur()
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func updateBlur(style: UIBlurEffect.Style, intensity: Double) {
|
|
24
|
+
self.blurStyle = style
|
|
25
|
+
self.intensity = intensity
|
|
26
|
+
setupBlur()
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private func setupBlur() {
|
|
30
|
+
// Clean up existing animator
|
|
31
|
+
animator?.stopAnimation(true)
|
|
32
|
+
animator?.finishAnimation(at: .current)
|
|
33
|
+
animator = nil
|
|
34
|
+
|
|
35
|
+
// Reset effect
|
|
36
|
+
effect = nil
|
|
37
|
+
|
|
38
|
+
// Create new animator
|
|
39
|
+
animator = UIViewPropertyAnimator(duration: 1, curve: .linear)
|
|
40
|
+
animator?.addAnimations { [weak self] in
|
|
41
|
+
self?.effect = UIBlurEffect(style: self?.blurStyle ?? .systemMaterial)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Set intensity and pause
|
|
45
|
+
animator?.fractionComplete = intensity
|
|
46
|
+
animator?.pauseAnimation()
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
deinit {
|
|
50
|
+
animator?.stopAnimation(true)
|
|
51
|
+
animator?.finishAnimation(at: .current)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// MARK: - SwiftUI Blur Wrapper
|
|
56
|
+
|
|
57
|
+
struct Blur: UIViewRepresentable {
|
|
58
|
+
var style: UIBlurEffect.Style = .systemMaterial
|
|
59
|
+
var intensity: Double = 1.0
|
|
60
|
+
|
|
61
|
+
func makeUIView(context: Context) -> BlurEffectView {
|
|
62
|
+
let effectView = BlurEffectView(effect: nil)
|
|
63
|
+
effectView.updateBlur(style: style, intensity: intensity)
|
|
64
|
+
return effectView
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
func updateUIView(_ uiView: BlurEffectView, context: Context) {
|
|
68
|
+
uiView.updateBlur(style: style, intensity: intensity)
|
|
69
|
+
}
|
|
70
|
+
}
|