mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 05:15:49 +08:00
iOS: Support <ActivityIndicator> component
Summary: Setup for using <ActivityIndicator> component in Fabric. Reviewed By: shergin Differential Revision: D8107528 fbshipit-source-id: e3ba46d1538f5d5a2fa6f75639caaaa51156c452
This commit is contained in:
committed by
Facebook Github Bot
parent
7014a30baa
commit
8bfe78c723
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#import <React/RCTViewComponentView.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
/**
|
||||
* UIView class for root <ShimmeringView> component.
|
||||
*/
|
||||
@interface RCTActivityIndicatorViewComponentView : RCTViewComponentView
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
#import "RCTActivityIndicatorViewComponentView.h"
|
||||
|
||||
#import <fabric/activityindicator/ActivityIndicatorViewProps.h>
|
||||
|
||||
using namespace facebook::react;
|
||||
|
||||
static UIActivityIndicatorViewStyle convertActivityIndicatorViewStyle(const ActivityIndicatorViewSize &size) {
|
||||
switch (size) {
|
||||
case ActivityIndicatorViewSize::Small:
|
||||
return UIActivityIndicatorViewStyleWhite;
|
||||
case ActivityIndicatorViewSize::Large:
|
||||
return UIActivityIndicatorViewStyleWhiteLarge;
|
||||
}
|
||||
}
|
||||
|
||||
@implementation RCTActivityIndicatorViewComponentView {
|
||||
UIActivityIndicatorView *_activityIndicatorView;
|
||||
}
|
||||
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:self.bounds];
|
||||
_activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
||||
|
||||
auto &&defaultProps = ActivityIndicatorViewProps();
|
||||
|
||||
if (defaultProps.animating) {
|
||||
[_activityIndicatorView startAnimating];
|
||||
} else {
|
||||
[_activityIndicatorView stopAnimating];
|
||||
}
|
||||
_activityIndicatorView.color = [UIColor colorWithCGColor:defaultProps.color.get()];
|
||||
_activityIndicatorView.hidesWhenStopped = defaultProps.hidesWhenStopped;
|
||||
_activityIndicatorView.activityIndicatorViewStyle = convertActivityIndicatorViewStyle(defaultProps.size);
|
||||
|
||||
[self addSubview:_activityIndicatorView];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
|
||||
{
|
||||
if (!oldProps) {
|
||||
oldProps = _props ?: std::make_shared<ActivityIndicatorViewProps>();
|
||||
}
|
||||
_props = props;
|
||||
|
||||
[super updateProps:props oldProps:oldProps];
|
||||
|
||||
auto oldViewProps = *std::dynamic_pointer_cast<const ActivityIndicatorViewProps>(oldProps);
|
||||
auto newViewProps = *std::dynamic_pointer_cast<const ActivityIndicatorViewProps>(props);
|
||||
|
||||
if (oldViewProps.animating != newViewProps.animating) {
|
||||
if (newViewProps.animating) {
|
||||
[_activityIndicatorView startAnimating];
|
||||
} else {
|
||||
[_activityIndicatorView stopAnimating];
|
||||
}
|
||||
}
|
||||
|
||||
if (oldViewProps.color.get() != newViewProps.color.get()) {
|
||||
_activityIndicatorView.color = [UIColor colorWithCGColor:newViewProps.color.get()];
|
||||
}
|
||||
|
||||
// TODO: This prop should be deprecated.
|
||||
if (oldViewProps.hidesWhenStopped != newViewProps.hidesWhenStopped) {
|
||||
_activityIndicatorView.hidesWhenStopped = newViewProps.hidesWhenStopped;
|
||||
}
|
||||
|
||||
if (oldViewProps.size != newViewProps.size) {
|
||||
_activityIndicatorView.activityIndicatorViewStyle = convertActivityIndicatorViewStyle(newViewProps.size);
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user