forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
iOS: Support <ActivityIndicator> component
Summary: Setup for using <ActivityIndicator> component in Fabric. Reviewed By: shergin Differential Revision: D8107528 fbshipit-source-id: e3ba46d1538f5d5a2fa6f75639caaaa51156c452
- Loading branch information
1 parent
7014a30
commit 8bfe78c
Showing
14 changed files
with
382 additions
and
8 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
21 changes: 21 additions & 0 deletions
21
.../Fabric/Mounting/ComponentViews/ActivityIndicator/RCTActivityIndicatorViewComponentView.h
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 |
---|---|---|
@@ -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 |
84 changes: 84 additions & 0 deletions
84
...Fabric/Mounting/ComponentViews/ActivityIndicator/RCTActivityIndicatorViewComponentView.mm
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 |
---|---|---|
@@ -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 |
19 changes: 19 additions & 0 deletions
19
ReactCommon/fabric/activityindicator/ActivityIndicatorViewComponentDescriptor.h
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fabric/activityindicator/ActivityIndicatorViewShadowNode.h> | ||
#include <fabric/core/ConcreteComponentDescriptor.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
using ActivityIndicatorViewComponentDescriptor = ConcreteComponentDescriptor<ActivityIndicatorViewShadowNode>; | ||
|
||
} // namespace react | ||
} // namespace facebook |
23 changes: 23 additions & 0 deletions
23
ReactCommon/fabric/activityindicator/ActivityIndicatorViewProps.cpp
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#include <fabric/activityindicator/ActivityIndicatorViewProps.h> | ||
#include <fabric/activityindicator/conversions.h> | ||
#include <fabric/core/propsConversions.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
ActivityIndicatorViewProps::ActivityIndicatorViewProps(const ActivityIndicatorViewProps &sourceProps, const RawProps &rawProps): | ||
ViewProps(sourceProps, rawProps), | ||
animating(convertRawProp(rawProps, "animating", sourceProps.animating)), | ||
color(convertRawProp(rawProps, "color", sourceProps.color)), | ||
hidesWhenStopped(convertRawProp(rawProps, "hidesWhenStopped", sourceProps.hidesWhenStopped)), | ||
size(convertRawProp(rawProps, "size", sourceProps.size)) {} | ||
|
||
} // namespace react | ||
} // namespace facebook |
32 changes: 32 additions & 0 deletions
32
ReactCommon/fabric/activityindicator/ActivityIndicatorViewProps.h
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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#include <fabric/activityindicator/primitives.h> | ||
#include <fabric/graphics/Color.h> | ||
#include <fabric/view/ViewProps.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
// TODO (T28334063): Consider for codegen. | ||
class ActivityIndicatorViewProps final: | ||
public ViewProps { | ||
|
||
public: | ||
ActivityIndicatorViewProps() = default; | ||
ActivityIndicatorViewProps(const ActivityIndicatorViewProps &sourceProps, const RawProps &rawProps); | ||
|
||
#pragma mark - Props | ||
|
||
const bool animating {true}; | ||
const SharedColor color {colorFromComponents({153/255.0, 153/255.0, 153/255.0, 1.0})}; // #999999 | ||
const bool hidesWhenStopped {true}; | ||
const ActivityIndicatorViewSize size {ActivityIndicatorViewSize::Small}; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
18 changes: 18 additions & 0 deletions
18
ReactCommon/fabric/activityindicator/ActivityIndicatorViewShadowNode.cpp
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#include <fabric/activityindicator/ActivityIndicatorViewShadowNode.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
ComponentName ActivityIndicatorViewShadowNode::getComponentName() const { | ||
return ComponentName("ActivityIndicatorView"); | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
30 changes: 30 additions & 0 deletions
30
ReactCommon/fabric/activityindicator/ActivityIndicatorViewShadowNode.h
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fabric/activityindicator/ActivityIndicatorViewProps.h> | ||
#include <fabric/view/ConcreteViewShadowNode.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
/* | ||
* `ShadowNode` for <ActivityIndicatorView> component. | ||
*/ | ||
class ActivityIndicatorViewShadowNode final: | ||
public ConcreteViewShadowNode<ActivityIndicatorViewProps> { | ||
|
||
public: | ||
|
||
using ConcreteViewShadowNode::ConcreteViewShadowNode; | ||
|
||
ComponentName getComponentName() const override; | ||
}; | ||
|
||
} // namespace react | ||
} // namespace facebook |
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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
load("//configurations/buck/apple:flag_defs.bzl", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_application_ios_flags", "get_debug_preprocessor_flags") | ||
load("//ReactNative:DEFS.bzl", "ANDROID", "APPLE", "IS_OSS_BUILD", "get_apple_inspector_flags", "react_native_xplat_target", "rn_xplat_cxx_library") | ||
|
||
APPLE_COMPILER_FLAGS = [] | ||
|
||
if not IS_OSS_BUILD: | ||
load("@xplat//configurations/buck/apple:flag_defs.bzl", "flags", "get_static_library_ios_flags") | ||
|
||
APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), "compiler_flags") | ||
|
||
rn_xplat_cxx_library( | ||
name = "activityindicator", | ||
srcs = glob( | ||
["**/*.cpp"], | ||
exclude = glob(["tests/**/*.cpp"]), | ||
), | ||
headers = [], | ||
header_namespace = "", | ||
exported_headers = subdir_glob( | ||
[ | ||
("", "*.h"), | ||
], | ||
prefix = "fabric/activityindicator", | ||
), | ||
compiler_flags = [ | ||
"-fexceptions", | ||
"-frtti", | ||
"-std=c++14", | ||
"-Wall", | ||
], | ||
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS, | ||
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(), | ||
fbobjc_tests = [ | ||
":tests", | ||
], | ||
macosx_tests_override = [], | ||
platforms = (ANDROID, APPLE), | ||
preprocessor_flags = [ | ||
"-DLOG_TAG=\"ReactNative\"", | ||
"-DWITH_FBSYSTRACE=1", | ||
], | ||
tests = [], | ||
visibility = ["PUBLIC"], | ||
deps = [ | ||
"xplat//fbsystrace:fbsystrace", | ||
"xplat//folly:headers_only", | ||
"xplat//folly:memory", | ||
"xplat//folly:molly", | ||
"xplat//third-party/glog:glog", | ||
"xplat//yoga:yoga", | ||
react_native_xplat_target("fabric/debug:debug"), | ||
react_native_xplat_target("fabric/core:core"), | ||
react_native_xplat_target("fabric/graphics:graphics"), | ||
react_native_xplat_target("fabric/view:view"), | ||
], | ||
) | ||
|
||
if not IS_OSS_BUILD: | ||
load("@xplat//build_defs:fb_xplat_cxx_test.bzl", "fb_xplat_cxx_test") | ||
|
||
fb_xplat_cxx_test( | ||
name = "tests", | ||
srcs = glob(["tests/**/*.cpp"]), | ||
headers = glob(["tests/**/*.h"]), | ||
contacts = ["[email protected]"], | ||
compiler_flags = [ | ||
"-fexceptions", | ||
"-frtti", | ||
"-std=c++14", | ||
"-Wall", | ||
], | ||
platforms = APPLE, | ||
deps = [ | ||
"xplat//folly:molly", | ||
"xplat//third-party/gmock:gtest", | ||
":activityindicator", | ||
], | ||
) |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <fabric/activityindicator/primitives.h> | ||
#include <folly/dynamic.h> | ||
|
||
namespace facebook { | ||
namespace react { | ||
|
||
inline void fromDynamic(const folly::dynamic &value, ActivityIndicatorViewSize &result) { | ||
auto string = value.asString(); | ||
if (string == "large") { result = ActivityIndicatorViewSize::Large; return; } | ||
if (string == "small") { result = ActivityIndicatorViewSize::Small; return; } | ||
abort(); | ||
} | ||
|
||
inline std::string toString(const ActivityIndicatorViewSize &value) { | ||
switch (value) { | ||
case ActivityIndicatorViewSize::Large: return "large"; | ||
case ActivityIndicatorViewSize::Small: return "small"; | ||
} | ||
} | ||
|
||
} // namespace react | ||
} // namespace facebook |
Oops, something went wrong.