react-native-gleam 1.0.0-beta.1 → 1.0.0-beta.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.
Files changed (2) hide show
  1. package/ios/GleamView.mm +25 -13
  2. package/package.json +1 -1
package/ios/GleamView.mm CHANGED
@@ -55,7 +55,6 @@ static void _unregisterView(GleamView *view) {
55
55
  #pragma mark - GleamView
56
56
 
57
57
  @implementation GleamView {
58
- UIView *_contentView;
59
58
  CAGradientLayer *_shimmerLayer;
60
59
  BOOL _loading;
61
60
  BOOL _wasLoading;
@@ -111,10 +110,6 @@ static void _unregisterView(GleamView *view) {
111
110
  _shimmerOpacity = 1.0;
112
111
  _contentAlpha = 0.0;
113
112
 
114
- _contentView = [[UIView alloc] init];
115
- _contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
116
- _contentView.alpha = 0.0;
117
-
118
113
  _shimmerLayer = [CAGradientLayer layer];
119
114
  // Disable implicit animations on the gradient layer
120
115
  _shimmerLayer.actions = @{
@@ -126,11 +121,18 @@ static void _unregisterView(GleamView *view) {
126
121
  @"transform": [NSNull null],
127
122
  };
128
123
 
129
- self.contentView = _contentView;
130
124
  }
131
125
  return self;
132
126
  }
133
127
 
128
+ - (void)mountChildComponentView:(UIView<RCTComponentViewProtocol> *)childComponentView index:(NSInteger)index
129
+ {
130
+ [super mountChildComponentView:childComponentView index:index];
131
+ if (_loading) {
132
+ childComponentView.alpha = 0.0;
133
+ }
134
+ }
135
+
134
136
  - (void)layoutSubviews
135
137
  {
136
138
  [super layoutSubviews];
@@ -138,7 +140,10 @@ static void _unregisterView(GleamView *view) {
138
140
  _shimmerLayer.cornerRadius = self.layer.cornerRadius;
139
141
  _shimmerLayer.maskedCorners = self.layer.maskedCorners;
140
142
 
141
- if (_loading && !_isRegistered) {
143
+ if (_loading) {
144
+ if (_shimmerLayer.superlayer != self.layer) {
145
+ [self.layer addSublayer:_shimmerLayer];
146
+ }
142
147
  [self _registerClock];
143
148
  }
144
149
  }
@@ -257,7 +262,7 @@ static void _unregisterView(GleamView *view) {
257
262
  switch (_transitionTypeValue) {
258
263
  case 1: { // Shrink — scale down with mask clipping
259
264
  _contentAlpha = eased;
260
- _contentView.alpha = _contentAlpha;
265
+ [self _setChildrenAlpha:_contentAlpha];
261
266
  CGFloat shrinkOpacity = 1.0 - fmin(eased * 2.5, 1.0);
262
267
  _shimmerLayer.opacity = shrinkOpacity;
263
268
  CGFloat scale = 1.0 - eased * 0.5;
@@ -278,7 +283,7 @@ static void _unregisterView(GleamView *view) {
278
283
  }
279
284
  case 2: { // Collapse — vertically then horizontally via clip rect
280
285
  _contentAlpha = eased;
281
- _contentView.alpha = _contentAlpha;
286
+ [self _setChildrenAlpha:_contentAlpha];
282
287
  CGFloat collapseOpacity = 1.0 - fmin(eased * 2.5, 1.0);
283
288
  _shimmerLayer.opacity = collapseOpacity;
284
289
  CGRect bounds = self.bounds;
@@ -301,7 +306,7 @@ static void _unregisterView(GleamView *view) {
301
306
  }
302
307
  default: // Fade
303
308
  _contentAlpha = eased;
304
- _contentView.alpha = _contentAlpha;
309
+ [self _setChildrenAlpha:_contentAlpha];
305
310
  _shimmerOpacity = 1.0 - eased;
306
311
  _shimmerLayer.opacity = _shimmerOpacity;
307
312
  break;
@@ -317,6 +322,13 @@ static void _unregisterView(GleamView *view) {
317
322
  }
318
323
  }
319
324
 
325
+ - (void)_setChildrenAlpha:(CGFloat)alpha
326
+ {
327
+ for (UIView *subview in self.subviews) {
328
+ subview.alpha = alpha;
329
+ }
330
+ }
331
+
320
332
  - (void)_updateGradientPosition
321
333
  {
322
334
  CGFloat progress = [self _computeProgress];
@@ -378,7 +390,7 @@ static void _unregisterView(GleamView *view) {
378
390
  _isTransitioning = NO;
379
391
  _contentAlpha = 0.0;
380
392
  _shimmerOpacity = 1.0;
381
- _contentView.alpha = 0.0;
393
+ [self _setChildrenAlpha:0.0];
382
394
  _shimmerLayer.opacity = 1.0;
383
395
  _shimmerLayer.frame = self.bounds;
384
396
  if (_shimmerLayer.superlayer != self.layer) {
@@ -396,7 +408,7 @@ static void _unregisterView(GleamView *view) {
396
408
  // Clock stays registered to drive the transition
397
409
  } else {
398
410
  [self _unregisterClock];
399
- _contentView.alpha = 1.0;
411
+ [self _setChildrenAlpha:1.0];
400
412
  _shimmerLayer.opacity = 0.0;
401
413
  [_shimmerLayer removeFromSuperlayer];
402
414
  [self _emitTransitionEnd:YES];
@@ -408,7 +420,7 @@ static void _unregisterView(GleamView *view) {
408
420
  {
409
421
  _isTransitioning = NO;
410
422
  [self _unregisterClock];
411
- _contentView.alpha = 1.0;
423
+ [self _setChildrenAlpha:1.0];
412
424
  _shimmerLayer.opacity = 0.0;
413
425
  _shimmerLayer.transform = CATransform3DIdentity;
414
426
  _shimmerLayer.mask = nil;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gleam",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Native-powered shimmer loading effect for React Native",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",