@momo-kits/glass-view 0.167.1-duo.3
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/GlassView.podspec +20 -0
- package/LICENSE +20 -0
- package/ios/RNGlassView.h +10 -0
- package/ios/RNGlassView.mm +153 -0
- package/package.json +43 -0
- package/src/RNGlassViewNativeComponent.ts +16 -0
- package/src/index.tsx +32 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "json"
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = "GlassView"
|
|
7
|
+
s.version = package["version"]
|
|
8
|
+
s.summary = package["description"]
|
|
9
|
+
s.homepage = package["homepage"]
|
|
10
|
+
s.license = package["license"]
|
|
11
|
+
s.authors = package["author"]
|
|
12
|
+
|
|
13
|
+
s.platforms = { :ios => min_ios_version_supported }
|
|
14
|
+
s.source = { :git => "https://www.npmjs.com/.git", :tag => "#{s.version}" }
|
|
15
|
+
|
|
16
|
+
s.source_files = "ios/**/*.{h,m,mm}"
|
|
17
|
+
s.private_header_files = "ios/**/*.h"
|
|
18
|
+
|
|
19
|
+
install_modules_dependencies(s)
|
|
20
|
+
end
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 dung.pham2
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
#import "RNGlassView.h"
|
|
2
|
+
|
|
3
|
+
#import <react/renderer/components/GlassViewSpec/ComponentDescriptors.h>
|
|
4
|
+
#import <react/renderer/components/GlassViewSpec/EventEmitters.h>
|
|
5
|
+
#import <react/renderer/components/GlassViewSpec/Props.h>
|
|
6
|
+
#import <react/renderer/components/GlassViewSpec/RCTComponentViewHelpers.h>
|
|
7
|
+
|
|
8
|
+
#import <React/RCTConversions.h>
|
|
9
|
+
|
|
10
|
+
#import "RCTFabricComponentsPlugins.h"
|
|
11
|
+
|
|
12
|
+
using namespace facebook::react;
|
|
13
|
+
|
|
14
|
+
static const NSTimeInterval kEffectAnimationDuration = 0.25;
|
|
15
|
+
static const float kShadowOpacity = 0.16;
|
|
16
|
+
static const CGFloat kShadowRadius = 16;
|
|
17
|
+
static const CGFloat kShadowOffsetY = 6;
|
|
18
|
+
|
|
19
|
+
@interface RNGlassView () <RCTRNGlassViewViewProtocol>
|
|
20
|
+
@end
|
|
21
|
+
|
|
22
|
+
@implementation RNGlassView {
|
|
23
|
+
UIView *_container;
|
|
24
|
+
// shadow lives on its own layer since the effect view must clip to round its corners
|
|
25
|
+
UIView *_shadowView;
|
|
26
|
+
UIVisualEffectView *_effectView;
|
|
27
|
+
RNGlassViewEffect _effect;
|
|
28
|
+
UIColor *_tintColor;
|
|
29
|
+
BOOL _interactive;
|
|
30
|
+
BOOL _useShadow;
|
|
31
|
+
CGFloat _cornerRadius;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
+ (ComponentDescriptorProvider)componentDescriptorProvider {
|
|
35
|
+
return concreteComponentDescriptorProvider<RNGlassViewComponentDescriptor>();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (instancetype)initWithFrame:(CGRect)frame {
|
|
39
|
+
if (self = [super initWithFrame:frame]) {
|
|
40
|
+
static const auto defaultProps = std::make_shared<const RNGlassViewProps>();
|
|
41
|
+
_props = defaultProps;
|
|
42
|
+
_effect = RNGlassViewEffect::Glass;
|
|
43
|
+
|
|
44
|
+
_container = [[UIView alloc] initWithFrame:frame];
|
|
45
|
+
|
|
46
|
+
_shadowView = [[UIView alloc] initWithFrame:frame];
|
|
47
|
+
_shadowView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
48
|
+
_shadowView.layer.shadowColor = UIColor.blackColor.CGColor;
|
|
49
|
+
_shadowView.layer.shadowRadius = kShadowRadius;
|
|
50
|
+
_shadowView.layer.shadowOffset = CGSizeMake(0, kShadowOffsetY);
|
|
51
|
+
_shadowView.layer.shadowOpacity = 0;
|
|
52
|
+
[_container addSubview:_shadowView];
|
|
53
|
+
|
|
54
|
+
_effectView = [[UIVisualEffectView alloc] initWithEffect:nil];
|
|
55
|
+
_effectView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
56
|
+
_effectView.layer.cornerCurve = kCACornerCurveContinuous;
|
|
57
|
+
[_container addSubview:_effectView];
|
|
58
|
+
|
|
59
|
+
self.contentView = _container;
|
|
60
|
+
[self applyEffectAnimated:NO];
|
|
61
|
+
}
|
|
62
|
+
return self;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
- (void)layoutSubviews {
|
|
66
|
+
[super layoutSubviews];
|
|
67
|
+
_shadowView.layer.shadowPath =
|
|
68
|
+
[UIBezierPath bezierPathWithRoundedRect:_shadowView.bounds cornerRadius:_cornerRadius].CGPath;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (UIVisualEffect *)buildEffect {
|
|
72
|
+
switch (_effect) {
|
|
73
|
+
case RNGlassViewEffect::None:
|
|
74
|
+
return nil;
|
|
75
|
+
case RNGlassViewEffect::Blur:
|
|
76
|
+
return [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
|
|
77
|
+
case RNGlassViewEffect::Glass:
|
|
78
|
+
case RNGlassViewEffect::ClearGlass:
|
|
79
|
+
if (@available(iOS 26.0, *)) {
|
|
80
|
+
UIGlassEffect *glass = [UIGlassEffect
|
|
81
|
+
effectWithStyle:_effect == RNGlassViewEffect::ClearGlass ? UIGlassEffectStyleClear
|
|
82
|
+
: UIGlassEffectStyleRegular];
|
|
83
|
+
glass.tintColor = _tintColor;
|
|
84
|
+
glass.interactive = _interactive;
|
|
85
|
+
return glass;
|
|
86
|
+
}
|
|
87
|
+
return [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
|
|
88
|
+
}
|
|
89
|
+
return nil;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// glass materializes when its effect is set inside an animation block, not via alpha
|
|
93
|
+
- (void)applyEffectAnimated:(BOOL)animated {
|
|
94
|
+
UIVisualEffect *effect = [self buildEffect];
|
|
95
|
+
float shadowOpacity = _useShadow && effect != nil ? kShadowOpacity : 0;
|
|
96
|
+
|
|
97
|
+
if (animated) {
|
|
98
|
+
CABasicAnimation *fade = [CABasicAnimation animationWithKeyPath:@"shadowOpacity"];
|
|
99
|
+
fade.fromValue = @(_shadowView.layer.presentationLayer.shadowOpacity);
|
|
100
|
+
fade.toValue = @(shadowOpacity);
|
|
101
|
+
fade.duration = kEffectAnimationDuration;
|
|
102
|
+
[_shadowView.layer addAnimation:fade forKey:@"shadowOpacity"];
|
|
103
|
+
}
|
|
104
|
+
_shadowView.layer.shadowOpacity = shadowOpacity;
|
|
105
|
+
|
|
106
|
+
if (!animated) {
|
|
107
|
+
_effectView.effect = effect;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
[UIView animateWithDuration:kEffectAnimationDuration
|
|
111
|
+
animations:^{
|
|
112
|
+
self->_effectView.effect = effect;
|
|
113
|
+
}];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
- (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps {
|
|
117
|
+
const auto &newProps = *std::static_pointer_cast<const RNGlassViewProps>(props);
|
|
118
|
+
const auto &prevProps = *std::static_pointer_cast<const RNGlassViewProps>(_props);
|
|
119
|
+
|
|
120
|
+
if (newProps.cornerRadius != prevProps.cornerRadius) {
|
|
121
|
+
_cornerRadius = newProps.cornerRadius;
|
|
122
|
+
_effectView.layer.cornerRadius = _cornerRadius;
|
|
123
|
+
_effectView.clipsToBounds = _cornerRadius > 0;
|
|
124
|
+
[self setNeedsLayout];
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (newProps.effect != prevProps.effect || newProps.glassTintColor != prevProps.glassTintColor ||
|
|
128
|
+
newProps.interactive != prevProps.interactive || newProps.useShadow != prevProps.useShadow) {
|
|
129
|
+
_effect = newProps.effect;
|
|
130
|
+
_tintColor = RCTUIColorFromSharedColor(newProps.glassTintColor);
|
|
131
|
+
_interactive = newProps.interactive;
|
|
132
|
+
_useShadow = newProps.useShadow;
|
|
133
|
+
[self applyEffectAnimated:oldProps != nullptr];
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
[super updateProps:props oldProps:oldProps];
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
- (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView
|
|
140
|
+
index:(NSInteger)index {
|
|
141
|
+
[_effectView.contentView insertSubview:childComponentView atIndex:index];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
- (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView
|
|
145
|
+
index:(NSInteger)index {
|
|
146
|
+
[childComponentView removeFromSuperview];
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@end
|
|
150
|
+
|
|
151
|
+
Class<RCTComponentViewProtocol> RNGlassViewCls(void) {
|
|
152
|
+
return RNGlassView.class;
|
|
153
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@momo-kits/glass-view",
|
|
3
|
+
"version": "0.167.1-duo.3",
|
|
4
|
+
"description": "iOS liquid glass (UIGlassEffect) background view with a blur fallback.",
|
|
5
|
+
"main": "./src/index.tsx",
|
|
6
|
+
"files": [
|
|
7
|
+
"src",
|
|
8
|
+
"ios",
|
|
9
|
+
"*.podspec",
|
|
10
|
+
"!ios/build",
|
|
11
|
+
"!**/.*"
|
|
12
|
+
],
|
|
13
|
+
"keywords": [
|
|
14
|
+
"react-native",
|
|
15
|
+
"ios",
|
|
16
|
+
"liquid-glass",
|
|
17
|
+
"blur"
|
|
18
|
+
],
|
|
19
|
+
"author": "MoMo Team",
|
|
20
|
+
"license": "MIT",
|
|
21
|
+
"homepage": "https://www.npmjs.com/package/@momo-kits/glass-view",
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"react": "*",
|
|
27
|
+
"react-native": "*"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18.0.0"
|
|
31
|
+
},
|
|
32
|
+
"codegenConfig": {
|
|
33
|
+
"name": "GlassViewSpec",
|
|
34
|
+
"type": "components",
|
|
35
|
+
"jsSrcsDir": "src",
|
|
36
|
+
"ios": {
|
|
37
|
+
"componentProvider": {
|
|
38
|
+
"RNGlassView": "RNGlassView"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {}
|
|
43
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
|
|
2
|
+
import type { ColorValue, ViewProps } from 'react-native';
|
|
3
|
+
import type {
|
|
4
|
+
Float,
|
|
5
|
+
WithDefault,
|
|
6
|
+
} from 'react-native/Libraries/Types/CodegenTypes';
|
|
7
|
+
|
|
8
|
+
export interface NativeProps extends ViewProps {
|
|
9
|
+
effect?: WithDefault<'glass' | 'clearGlass' | 'blur' | 'none', 'glass'>;
|
|
10
|
+
glassTintColor?: ColorValue;
|
|
11
|
+
interactive?: boolean;
|
|
12
|
+
cornerRadius?: Float;
|
|
13
|
+
useShadow?: boolean;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default codegenNativeComponent<NativeProps>('RNGlassView');
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Platform, View, type ColorValue, type ViewProps } from 'react-native';
|
|
3
|
+
import RNGlassViewNativeComponent from './RNGlassViewNativeComponent';
|
|
4
|
+
|
|
5
|
+
export type GlassEffect = 'glass' | 'clearGlass' | 'blur' | 'none';
|
|
6
|
+
|
|
7
|
+
export interface GlassViewProps extends ViewProps {
|
|
8
|
+
/**
|
|
9
|
+
* glass needs iOS 26+, older iOS falls back to a system blur; 'none' animates the material out
|
|
10
|
+
*/
|
|
11
|
+
effect?: GlassEffect;
|
|
12
|
+
glassTintColor?: ColorValue;
|
|
13
|
+
interactive?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* rounds the material; RN borderRadius can't clip the effect view
|
|
16
|
+
*/
|
|
17
|
+
cornerRadius?: number;
|
|
18
|
+
/**
|
|
19
|
+
* drop shadow while the material is shown
|
|
20
|
+
*/
|
|
21
|
+
useShadow?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const GlassView: React.FC<GlassViewProps> = props => {
|
|
25
|
+
if (Platform.OS !== 'ios') {
|
|
26
|
+
return <View {...props} />;
|
|
27
|
+
}
|
|
28
|
+
return <RNGlassViewNativeComponent {...props} />;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { GlassView };
|
|
32
|
+
export default GlassView;
|