Skip to content

Commit 8bfe78c

Browse files
fkgozalifacebook-github-bot
authored andcommitted
iOS: Support <ActivityIndicator> component
Summary: Setup for using <ActivityIndicator> component in Fabric. Reviewed By: shergin Differential Revision: D8107528 fbshipit-source-id: e3ba46d1538f5d5a2fa6f75639caaaa51156c452
1 parent 7014a30 commit 8bfe78c

14 files changed

+382
-8
lines changed

RNTester/Podfile.lock

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ PODS:
2323
- React/Core
2424
- React/RCTWebSocket
2525
- React/fabric (1000.0.0):
26+
- React/fabric/activityindicator (= 1000.0.0)
2627
- React/fabric/attributedstring (= 1000.0.0)
2728
- React/fabric/core (= 1000.0.0)
2829
- React/fabric/debug (= 1000.0.0)
@@ -32,6 +33,8 @@ PODS:
3233
- React/fabric/textlayoutmanager (= 1000.0.0)
3334
- React/fabric/uimanager (= 1000.0.0)
3435
- React/fabric/view (= 1000.0.0)
36+
- React/fabric/activityindicator (1000.0.0):
37+
- Folly (= 2016.10.31.00)
3538
- React/fabric/attributedstring (1000.0.0):
3639
- Folly (= 2016.10.31.00)
3740
- React/fabric/core (1000.0.0):
@@ -141,7 +144,7 @@ SPEC CHECKSUMS:
141144
DoubleConversion: a9706f16e388b53ff12cca34473428ee29746a26
142145
Folly: c89ac2d5c6ab169cd7397ef27485c44f35f742c7
143146
glog: 3931855c9cc99c3fab1355fc162fe369162d8183
144-
React: 81df86644d0bca489723c964b33b005901ebfb3b
147+
React: 1fe0eb13d90b625d94c3b117c274dcfd2e760e11
145148
yoga: b1ce48b6cf950b98deae82838f5173ea7cf89e85
146149

147150
PODFILE CHECKSUM: 30aa63dcdbb3546a2bacdfd4e005bcca50c9b55c

React.podspec

+9
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@ Pod::Spec.new do |s|
135135
end
136136

137137
s.subspec "fabric" do |ss|
138+
ss.subspec "activityindicator" do |sss|
139+
sss.dependency "Folly", folly_version
140+
sss.compiler_flags = folly_compiler_flags
141+
sss.source_files = "ReactCommon/fabric/activityindicator/**/*.{cpp,h}"
142+
sss.exclude_files = "**/tests/*"
143+
sss.header_dir = "fabric/activityindicator"
144+
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Folly\"" }
145+
end
146+
138147
ss.subspec "attributedstring" do |sss|
139148
sss.dependency "Folly", folly_version
140149
sss.compiler_flags = folly_compiler_flags
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <UIKit/UIKit.h>
9+
10+
#import <React/RCTViewComponentView.h>
11+
12+
NS_ASSUME_NONNULL_BEGIN
13+
14+
/**
15+
* UIView class for root <ShimmeringView> component.
16+
*/
17+
@interface RCTActivityIndicatorViewComponentView : RCTViewComponentView
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "RCTActivityIndicatorViewComponentView.h"
9+
10+
#import <fabric/activityindicator/ActivityIndicatorViewProps.h>
11+
12+
using namespace facebook::react;
13+
14+
static UIActivityIndicatorViewStyle convertActivityIndicatorViewStyle(const ActivityIndicatorViewSize &size) {
15+
switch (size) {
16+
case ActivityIndicatorViewSize::Small:
17+
return UIActivityIndicatorViewStyleWhite;
18+
case ActivityIndicatorViewSize::Large:
19+
return UIActivityIndicatorViewStyleWhiteLarge;
20+
}
21+
}
22+
23+
@implementation RCTActivityIndicatorViewComponentView {
24+
UIActivityIndicatorView *_activityIndicatorView;
25+
}
26+
27+
- (instancetype)initWithFrame:(CGRect)frame
28+
{
29+
if (self = [super initWithFrame:frame]) {
30+
_activityIndicatorView = [[UIActivityIndicatorView alloc] initWithFrame:self.bounds];
31+
_activityIndicatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
32+
33+
auto &&defaultProps = ActivityIndicatorViewProps();
34+
35+
if (defaultProps.animating) {
36+
[_activityIndicatorView startAnimating];
37+
} else {
38+
[_activityIndicatorView stopAnimating];
39+
}
40+
_activityIndicatorView.color = [UIColor colorWithCGColor:defaultProps.color.get()];
41+
_activityIndicatorView.hidesWhenStopped = defaultProps.hidesWhenStopped;
42+
_activityIndicatorView.activityIndicatorViewStyle = convertActivityIndicatorViewStyle(defaultProps.size);
43+
44+
[self addSubview:_activityIndicatorView];
45+
}
46+
47+
return self;
48+
}
49+
50+
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
51+
{
52+
if (!oldProps) {
53+
oldProps = _props ?: std::make_shared<ActivityIndicatorViewProps>();
54+
}
55+
_props = props;
56+
57+
[super updateProps:props oldProps:oldProps];
58+
59+
auto oldViewProps = *std::dynamic_pointer_cast<const ActivityIndicatorViewProps>(oldProps);
60+
auto newViewProps = *std::dynamic_pointer_cast<const ActivityIndicatorViewProps>(props);
61+
62+
if (oldViewProps.animating != newViewProps.animating) {
63+
if (newViewProps.animating) {
64+
[_activityIndicatorView startAnimating];
65+
} else {
66+
[_activityIndicatorView stopAnimating];
67+
}
68+
}
69+
70+
if (oldViewProps.color.get() != newViewProps.color.get()) {
71+
_activityIndicatorView.color = [UIColor colorWithCGColor:newViewProps.color.get()];
72+
}
73+
74+
// TODO: This prop should be deprecated.
75+
if (oldViewProps.hidesWhenStopped != newViewProps.hidesWhenStopped) {
76+
_activityIndicatorView.hidesWhenStopped = newViewProps.hidesWhenStopped;
77+
}
78+
79+
if (oldViewProps.size != newViewProps.size) {
80+
_activityIndicatorView.activityIndicatorViewStyle = convertActivityIndicatorViewStyle(newViewProps.size);
81+
}
82+
}
83+
84+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <fabric/activityindicator/ActivityIndicatorViewShadowNode.h>
11+
#include <fabric/core/ConcreteComponentDescriptor.h>
12+
13+
namespace facebook {
14+
namespace react {
15+
16+
using ActivityIndicatorViewComponentDescriptor = ConcreteComponentDescriptor<ActivityIndicatorViewShadowNode>;
17+
18+
} // namespace react
19+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <fabric/activityindicator/ActivityIndicatorViewProps.h>
9+
#include <fabric/activityindicator/conversions.h>
10+
#include <fabric/core/propsConversions.h>
11+
12+
namespace facebook {
13+
namespace react {
14+
15+
ActivityIndicatorViewProps::ActivityIndicatorViewProps(const ActivityIndicatorViewProps &sourceProps, const RawProps &rawProps):
16+
ViewProps(sourceProps, rawProps),
17+
animating(convertRawProp(rawProps, "animating", sourceProps.animating)),
18+
color(convertRawProp(rawProps, "color", sourceProps.color)),
19+
hidesWhenStopped(convertRawProp(rawProps, "hidesWhenStopped", sourceProps.hidesWhenStopped)),
20+
size(convertRawProp(rawProps, "size", sourceProps.size)) {}
21+
22+
} // namespace react
23+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <fabric/activityindicator/primitives.h>
9+
#include <fabric/graphics/Color.h>
10+
#include <fabric/view/ViewProps.h>
11+
12+
namespace facebook {
13+
namespace react {
14+
15+
// TODO (T28334063): Consider for codegen.
16+
class ActivityIndicatorViewProps final:
17+
public ViewProps {
18+
19+
public:
20+
ActivityIndicatorViewProps() = default;
21+
ActivityIndicatorViewProps(const ActivityIndicatorViewProps &sourceProps, const RawProps &rawProps);
22+
23+
#pragma mark - Props
24+
25+
const bool animating {true};
26+
const SharedColor color {colorFromComponents({153/255.0, 153/255.0, 153/255.0, 1.0})}; // #999999
27+
const bool hidesWhenStopped {true};
28+
const ActivityIndicatorViewSize size {ActivityIndicatorViewSize::Small};
29+
};
30+
31+
} // namespace react
32+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include <fabric/activityindicator/ActivityIndicatorViewShadowNode.h>
9+
10+
namespace facebook {
11+
namespace react {
12+
13+
ComponentName ActivityIndicatorViewShadowNode::getComponentName() const {
14+
return ComponentName("ActivityIndicatorView");
15+
}
16+
17+
} // namespace react
18+
} // namespace facebook
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <fabric/activityindicator/ActivityIndicatorViewProps.h>
11+
#include <fabric/view/ConcreteViewShadowNode.h>
12+
13+
namespace facebook {
14+
namespace react {
15+
16+
/*
17+
* `ShadowNode` for <ActivityIndicatorView> component.
18+
*/
19+
class ActivityIndicatorViewShadowNode final:
20+
public ConcreteViewShadowNode<ActivityIndicatorViewProps> {
21+
22+
public:
23+
24+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
25+
26+
ComponentName getComponentName() const override;
27+
};
28+
29+
} // namespace react
30+
} // namespace facebook
+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
load("//configurations/buck/apple:flag_defs.bzl", "OBJC_ARC_PREPROCESSOR_FLAGS", "get_application_ios_flags", "get_debug_preprocessor_flags")
2+
load("//ReactNative:DEFS.bzl", "ANDROID", "APPLE", "IS_OSS_BUILD", "get_apple_inspector_flags", "react_native_xplat_target", "rn_xplat_cxx_library")
3+
4+
APPLE_COMPILER_FLAGS = []
5+
6+
if not IS_OSS_BUILD:
7+
load("@xplat//configurations/buck/apple:flag_defs.bzl", "flags", "get_static_library_ios_flags")
8+
9+
APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), "compiler_flags")
10+
11+
rn_xplat_cxx_library(
12+
name = "activityindicator",
13+
srcs = glob(
14+
["**/*.cpp"],
15+
exclude = glob(["tests/**/*.cpp"]),
16+
),
17+
headers = [],
18+
header_namespace = "",
19+
exported_headers = subdir_glob(
20+
[
21+
("", "*.h"),
22+
],
23+
prefix = "fabric/activityindicator",
24+
),
25+
compiler_flags = [
26+
"-fexceptions",
27+
"-frtti",
28+
"-std=c++14",
29+
"-Wall",
30+
],
31+
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
32+
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(),
33+
fbobjc_tests = [
34+
":tests",
35+
],
36+
macosx_tests_override = [],
37+
platforms = (ANDROID, APPLE),
38+
preprocessor_flags = [
39+
"-DLOG_TAG=\"ReactNative\"",
40+
"-DWITH_FBSYSTRACE=1",
41+
],
42+
tests = [],
43+
visibility = ["PUBLIC"],
44+
deps = [
45+
"xplat//fbsystrace:fbsystrace",
46+
"xplat//folly:headers_only",
47+
"xplat//folly:memory",
48+
"xplat//folly:molly",
49+
"xplat//third-party/glog:glog",
50+
"xplat//yoga:yoga",
51+
react_native_xplat_target("fabric/debug:debug"),
52+
react_native_xplat_target("fabric/core:core"),
53+
react_native_xplat_target("fabric/graphics:graphics"),
54+
react_native_xplat_target("fabric/view:view"),
55+
],
56+
)
57+
58+
if not IS_OSS_BUILD:
59+
load("@xplat//build_defs:fb_xplat_cxx_test.bzl", "fb_xplat_cxx_test")
60+
61+
fb_xplat_cxx_test(
62+
name = "tests",
63+
srcs = glob(["tests/**/*.cpp"]),
64+
headers = glob(["tests/**/*.h"]),
65+
contacts = ["[email protected]"],
66+
compiler_flags = [
67+
"-fexceptions",
68+
"-frtti",
69+
"-std=c++14",
70+
"-Wall",
71+
],
72+
platforms = APPLE,
73+
deps = [
74+
"xplat//folly:molly",
75+
"xplat//third-party/gmock:gtest",
76+
":activityindicator",
77+
],
78+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Copyright (c) 2015-present, Facebook, Inc.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <fabric/activityindicator/primitives.h>
11+
#include <folly/dynamic.h>
12+
13+
namespace facebook {
14+
namespace react {
15+
16+
inline void fromDynamic(const folly::dynamic &value, ActivityIndicatorViewSize &result) {
17+
auto string = value.asString();
18+
if (string == "large") { result = ActivityIndicatorViewSize::Large; return; }
19+
if (string == "small") { result = ActivityIndicatorViewSize::Small; return; }
20+
abort();
21+
}
22+
23+
inline std::string toString(const ActivityIndicatorViewSize &value) {
24+
switch (value) {
25+
case ActivityIndicatorViewSize::Large: return "large";
26+
case ActivityIndicatorViewSize::Small: return "small";
27+
}
28+
}
29+
30+
} // namespace react
31+
} // namespace facebook

0 commit comments

Comments
 (0)