This commit is contained in:
Yamozha
2021-04-02 02:24:13 +03:00
parent c23950b545
commit 7256d79e2c
31493 changed files with 3036630 additions and 0 deletions

View File

@ -0,0 +1,84 @@
load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "get_preprocessor_flags_for_build_mode")
load(
"//tools/build_defs/oss:rn_defs.bzl",
"ANDROID",
"APPLE",
"CXX",
"YOGA_CXX_TARGET",
"fb_xplat_cxx_test",
"get_apple_compiler_flags",
"get_apple_inspector_flags",
"react_native_xplat_target",
"rn_xplat_cxx_library",
"subdir_glob",
)
APPLE_COMPILER_FLAGS = get_apple_compiler_flags()
rn_xplat_cxx_library(
name = "scrollview",
srcs = glob(
["**/*.cpp"],
exclude = glob(["tests/**/*.cpp"]),
),
headers = glob(
["**/*.h"],
exclude = glob(["tests/**/*.h"]),
),
header_namespace = "",
exported_headers = subdir_glob(
[
("", "*.h"),
],
prefix = "react/components/scrollview",
),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_labels = ["supermodule:ios/default/public.react_native.infra"],
fbobjc_preprocessor_flags = get_preprocessor_flags_for_build_mode() + get_apple_inspector_flags(),
force_static = True,
macosx_tests_override = [],
platforms = (ANDROID, APPLE, CXX),
preprocessor_flags = [
"-DLOG_TAG=\"ReactNative\"",
"-DWITH_FBSYSTRACE=1",
],
tests = [":tests"],
visibility = ["PUBLIC"],
deps = [
"//xplat/fbsystrace:fbsystrace",
"//xplat/folly:headers_only",
"//xplat/folly:memory",
"//xplat/folly:molly",
"//xplat/third-party/glog:glog",
YOGA_CXX_TARGET,
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/components/view:view"),
],
)
fb_xplat_cxx_test(
name = "tests",
srcs = glob(["tests/**/*.cpp"]),
headers = glob(["tests/**/*.h"]),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
contacts = ["oncall+react_native@xmail.facebook.com"],
platforms = (ANDROID, APPLE, CXX),
deps = [
":scrollview",
"//xplat/folly:molly",
"//xplat/third-party/gmock:gtest",
],
)

View File

@ -0,0 +1,95 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import <Foundation/Foundation.h>
#import <React/RCTDefines.h>
#import <React/RCTLog.h>
NS_ASSUME_NONNULL_BEGIN
@protocol RCTScrollViewProtocol <NSObject>
- (void)flashScrollIndicators;
- (void)scrollTo:(double)x y:(double)y animated:(BOOL)animated;
- (void)scrollToEnd:(BOOL)animated;
@end
RCT_EXTERN inline void
RCTScrollViewHandleCommand(id<RCTScrollViewProtocol> componentView, NSString const *commandName, NSArray const *args)
{
if ([commandName isEqualToString:@"flashScrollIndicators"]) {
#if RCT_DEBUG
if ([args count] != 0) {
RCTLogError(
@"%@ command %@ received %d arguments, expected %d.", @"ScrollView", commandName, (int)[args count], 1);
return;
}
#endif
[componentView flashScrollIndicators];
return;
}
if ([commandName isEqualToString:@"scrollTo"]) {
#if RCT_DEBUG
if ([args count] != 3) {
RCTLogError(
@"%@ command %@ received %d arguments, expected %d.", @"ScrollView", commandName, (int)[args count], 3);
return;
}
#endif
NSObject *arg0 = args[0];
#if RCT_DEBUG
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"float", @"ScrollView", commandName, @"1st")) {
return;
}
#endif
NSObject *arg1 = args[1];
#if RCT_DEBUG
if (!RCTValidateTypeOfViewCommandArgument(arg1, [NSNumber class], @"float", @"ScrollView", commandName, @"2nd")) {
return;
}
#endif
NSObject *arg2 = args[2];
#if RCT_DEBUG
if (!RCTValidateTypeOfViewCommandArgument(arg2, [NSNumber class], @"boolean", @"ScrollView", commandName, @"3rd")) {
return;
}
#endif
double x = [(NSNumber *)arg0 doubleValue];
double y = [(NSNumber *)arg1 doubleValue];
BOOL animated = [(NSNumber *)arg2 boolValue];
[componentView scrollTo:x y:y animated:animated];
return;
}
if ([commandName isEqualToString:@"scrollToEnd"]) {
#if RCT_DEBUG
if ([args count] != 1) {
RCTLogError(
@"%@ command %@ received %d arguments, expected %d.", @"ScrollView", commandName, (int)[args count], 1);
return;
}
#endif
NSObject *arg0 = args[0];
#if RCT_DEBUG
if (!RCTValidateTypeOfViewCommandArgument(arg0, [NSNumber class], @"boolean", @"ScrollView", commandName, @"1st")) {
return;
}
#endif
BOOL animated = [(NSNumber *)arg0 boolValue];
[componentView scrollToEnd:animated];
return;
}
}
NS_ASSUME_NONNULL_END

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <react/components/scrollview/ScrollViewShadowNode.h>
#include <react/core/ConcreteComponentDescriptor.h>
namespace facebook {
namespace react {
using ScrollViewComponentDescriptor =
ConcreteComponentDescriptor<ScrollViewShadowNode>;
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,99 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ScrollViewEventEmitter.h"
namespace facebook {
namespace react {
static jsi::Value scrollViewMetricsPayload(
jsi::Runtime &runtime,
const ScrollViewMetrics &scrollViewMetrics) {
auto payload = jsi::Object(runtime);
{
auto contentOffset = jsi::Object(runtime);
contentOffset.setProperty(runtime, "x", scrollViewMetrics.contentOffset.x);
contentOffset.setProperty(runtime, "y", scrollViewMetrics.contentOffset.y);
payload.setProperty(runtime, "contentOffset", contentOffset);
}
{
auto contentInset = jsi::Object(runtime);
contentInset.setProperty(
runtime, "top", scrollViewMetrics.contentInset.top);
contentInset.setProperty(
runtime, "left", scrollViewMetrics.contentInset.left);
contentInset.setProperty(
runtime, "bottom", scrollViewMetrics.contentInset.bottom);
contentInset.setProperty(
runtime, "right", scrollViewMetrics.contentInset.right);
payload.setProperty(runtime, "contentInset", contentInset);
}
{
auto contentSize = jsi::Object(runtime);
contentSize.setProperty(
runtime, "width", scrollViewMetrics.contentSize.width);
contentSize.setProperty(
runtime, "height", scrollViewMetrics.contentSize.height);
payload.setProperty(runtime, "contentSize", contentSize);
}
{
auto containerSize = jsi::Object(runtime);
containerSize.setProperty(
runtime, "width", scrollViewMetrics.containerSize.width);
containerSize.setProperty(
runtime, "height", scrollViewMetrics.containerSize.height);
payload.setProperty(runtime, "layoutMeasurement", containerSize);
}
payload.setProperty(runtime, "zoomScale", scrollViewMetrics.zoomScale);
return payload;
}
void ScrollViewEventEmitter::onScroll(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scroll", scrollViewMetrics);
}
void ScrollViewEventEmitter::onScrollBeginDrag(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scrollBeginDrag", scrollViewMetrics);
}
void ScrollViewEventEmitter::onScrollEndDrag(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("scrollEndDrag", scrollViewMetrics);
}
void ScrollViewEventEmitter::onMomentumScrollBegin(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("momentumScrollBegin", scrollViewMetrics);
}
void ScrollViewEventEmitter::onMomentumScrollEnd(
const ScrollViewMetrics &scrollViewMetrics) const {
dispatchScrollViewEvent("momentumScrollEnd", scrollViewMetrics);
}
void ScrollViewEventEmitter::dispatchScrollViewEvent(
const std::string &name,
const ScrollViewMetrics &scrollViewMetrics,
EventPriority priority) const {
dispatchEvent(
name,
[scrollViewMetrics](jsi::Runtime &runtime) {
return scrollViewMetricsPayload(runtime, scrollViewMetrics);
},
priority);
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <memory>
#include <folly/dynamic.h>
#include <react/components/view/ViewEventEmitter.h>
#include <react/core/EventEmitter.h>
#include <react/graphics/Geometry.h>
namespace facebook {
namespace react {
class ScrollViewMetrics {
public:
Size contentSize;
Point contentOffset;
EdgeInsets contentInset;
Size containerSize;
Float zoomScale;
};
class ScrollViewEventEmitter;
using SharedScrollViewEventEmitter =
std::shared_ptr<const ScrollViewEventEmitter>;
class ScrollViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
void onScroll(const ScrollViewMetrics &scrollViewMetrics) const;
void onScrollBeginDrag(const ScrollViewMetrics &scrollViewMetrics) const;
void onScrollEndDrag(const ScrollViewMetrics &scrollViewMetrics) const;
void onMomentumScrollBegin(const ScrollViewMetrics &scrollViewMetrics) const;
void onMomentumScrollEnd(const ScrollViewMetrics &scrollViewMetrics) const;
private:
void dispatchScrollViewEvent(
const std::string &name,
const ScrollViewMetrics &scrollViewMetrics,
EventPriority priority = EventPriority::AsynchronousBatched) const;
};
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,252 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ScrollViewProps.h"
#include <react/components/scrollview/conversions.h>
#include <react/debug/debugStringConvertibleUtils.h>
#include <react/graphics/conversions.h>
#include <react/core/propsConversions.h>
namespace facebook {
namespace react {
ScrollViewProps::ScrollViewProps(
const ScrollViewProps &sourceProps,
const RawProps &rawProps)
: ViewProps(sourceProps, rawProps),
alwaysBounceHorizontal(convertRawProp(
rawProps,
"alwaysBounceHorizontal",
sourceProps.alwaysBounceHorizontal,
{})),
alwaysBounceVertical(convertRawProp(
rawProps,
"alwaysBounceVertical",
sourceProps.alwaysBounceVertical,
{})),
bounces(convertRawProp(rawProps, "bounces", sourceProps.bounces, true)),
bouncesZoom(convertRawProp(
rawProps,
"bouncesZoom",
sourceProps.bouncesZoom,
true)),
canCancelContentTouches(convertRawProp(
rawProps,
"canCancelContentTouches",
sourceProps.canCancelContentTouches,
true)),
centerContent(convertRawProp(
rawProps,
"centerContent",
sourceProps.centerContent,
{})),
automaticallyAdjustContentInsets(convertRawProp(
rawProps,
"automaticallyAdjustContentInsets",
sourceProps.automaticallyAdjustContentInsets,
{})),
decelerationRate(convertRawProp(
rawProps,
"decelerationRate",
sourceProps.decelerationRate,
(Float)0.998)),
directionalLockEnabled(convertRawProp(
rawProps,
"directionalLockEnabled",
sourceProps.directionalLockEnabled,
{})),
indicatorStyle(convertRawProp(
rawProps,
"indicatorStyle",
sourceProps.indicatorStyle,
{})),
keyboardDismissMode(convertRawProp(
rawProps,
"keyboardDismissMode",
sourceProps.keyboardDismissMode,
{})),
maximumZoomScale(convertRawProp(
rawProps,
"maximumZoomScale",
sourceProps.maximumZoomScale,
(Float)1.0)),
minimumZoomScale(convertRawProp(
rawProps,
"minimumZoomScale",
sourceProps.minimumZoomScale,
(Float)1.0)),
scrollEnabled(convertRawProp(
rawProps,
"scrollEnabled",
sourceProps.scrollEnabled,
true)),
pagingEnabled(convertRawProp(
rawProps,
"pagingEnabled",
sourceProps.pagingEnabled,
{})),
pinchGestureEnabled(convertRawProp(
rawProps,
"pinchGestureEnabled",
sourceProps.pinchGestureEnabled,
true)),
scrollsToTop(convertRawProp(
rawProps,
"scrollsToTop",
sourceProps.scrollsToTop,
true)),
showsHorizontalScrollIndicator(convertRawProp(
rawProps,
"showsHorizontalScrollIndicator",
sourceProps.showsHorizontalScrollIndicator,
true)),
showsVerticalScrollIndicator(convertRawProp(
rawProps,
"showsVerticalScrollIndicator",
sourceProps.showsVerticalScrollIndicator,
true)),
scrollEventThrottle(convertRawProp(
rawProps,
"scrollEventThrottle",
sourceProps.scrollEventThrottle,
{})),
zoomScale(convertRawProp(
rawProps,
"zoomScale",
sourceProps.zoomScale,
(Float)1.0)),
contentInset(convertRawProp(
rawProps,
"contentInset",
sourceProps.contentInset,
{})),
scrollIndicatorInsets(convertRawProp(
rawProps,
"scrollIndicatorInsets",
sourceProps.scrollIndicatorInsets,
{})),
snapToInterval(convertRawProp(
rawProps,
"snapToInterval",
sourceProps.snapToInterval,
{})),
snapToAlignment(convertRawProp(
rawProps,
"snapToAlignment",
sourceProps.snapToAlignment,
{})) {}
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList ScrollViewProps::getDebugProps() const {
auto defaultScrollViewProps = ScrollViewProps{};
return ViewProps::getDebugProps() +
SharedDebugStringConvertibleList{
debugStringConvertibleItem(
"alwaysBounceHorizontal",
alwaysBounceHorizontal,
defaultScrollViewProps.alwaysBounceHorizontal),
debugStringConvertibleItem(
"alwaysBounceVertical",
alwaysBounceVertical,
defaultScrollViewProps.alwaysBounceVertical),
debugStringConvertibleItem(
"bounces", bounces, defaultScrollViewProps.bounces),
debugStringConvertibleItem(
"bouncesZoom", bouncesZoom, defaultScrollViewProps.bouncesZoom),
debugStringConvertibleItem(
"canCancelContentTouches",
canCancelContentTouches,
defaultScrollViewProps.canCancelContentTouches),
debugStringConvertibleItem(
"centerContent",
centerContent,
defaultScrollViewProps.centerContent),
debugStringConvertibleItem(
"automaticallyAdjustContentInsets",
automaticallyAdjustContentInsets,
defaultScrollViewProps.automaticallyAdjustContentInsets),
debugStringConvertibleItem(
"decelerationRate",
decelerationRate,
defaultScrollViewProps.decelerationRate),
debugStringConvertibleItem(
"directionalLockEnabled",
directionalLockEnabled,
defaultScrollViewProps.directionalLockEnabled),
debugStringConvertibleItem(
"indicatorStyle",
indicatorStyle,
defaultScrollViewProps.indicatorStyle),
debugStringConvertibleItem(
"keyboardDismissMode",
keyboardDismissMode,
defaultScrollViewProps.keyboardDismissMode),
debugStringConvertibleItem(
"maximumZoomScale",
maximumZoomScale,
defaultScrollViewProps.maximumZoomScale),
debugStringConvertibleItem(
"minimumZoomScale",
minimumZoomScale,
defaultScrollViewProps.minimumZoomScale),
debugStringConvertibleItem(
"scrollEnabled",
scrollEnabled,
defaultScrollViewProps.scrollEnabled),
debugStringConvertibleItem(
"pagingEnabled",
pagingEnabled,
defaultScrollViewProps.pagingEnabled),
debugStringConvertibleItem(
"pinchGestureEnabled",
pinchGestureEnabled,
defaultScrollViewProps.pinchGestureEnabled),
debugStringConvertibleItem(
"scrollsToTop",
scrollsToTop,
defaultScrollViewProps.scrollsToTop),
debugStringConvertibleItem(
"showsHorizontalScrollIndicator",
showsHorizontalScrollIndicator,
defaultScrollViewProps.showsHorizontalScrollIndicator),
debugStringConvertibleItem(
"showsVerticalScrollIndicator",
showsVerticalScrollIndicator,
defaultScrollViewProps.showsVerticalScrollIndicator),
debugStringConvertibleItem(
"scrollEventThrottle",
scrollEventThrottle,
defaultScrollViewProps.scrollEventThrottle),
debugStringConvertibleItem(
"zoomScale", zoomScale, defaultScrollViewProps.zoomScale),
debugStringConvertibleItem(
"contentInset",
contentInset,
defaultScrollViewProps.contentInset),
debugStringConvertibleItem(
"scrollIndicatorInsets",
scrollIndicatorInsets,
defaultScrollViewProps.scrollIndicatorInsets),
debugStringConvertibleItem(
"snapToInterval",
snapToInterval,
defaultScrollViewProps.snapToInterval),
debugStringConvertibleItem(
"snapToAlignment",
snapToAlignment,
defaultScrollViewProps.snapToAlignment),
};
}
#endif
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,58 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <react/components/scrollview/primitives.h>
#include <react/components/view/ViewProps.h>
namespace facebook {
namespace react {
// TODO (T28334063): Consider for codegen.
class ScrollViewProps final : public ViewProps {
public:
ScrollViewProps() = default;
ScrollViewProps(const ScrollViewProps &sourceProps, const RawProps &rawProps);
#pragma mark - Props
const bool alwaysBounceHorizontal{};
const bool alwaysBounceVertical{};
const bool bounces{true};
const bool bouncesZoom{true};
const bool canCancelContentTouches{true};
const bool centerContent{};
const bool automaticallyAdjustContentInsets{};
const Float decelerationRate{0.998};
const bool directionalLockEnabled{};
const ScrollViewIndicatorStyle indicatorStyle{};
const ScrollViewKeyboardDismissMode keyboardDismissMode{};
const Float maximumZoomScale{1.0};
const Float minimumZoomScale{1.0};
const bool scrollEnabled{true};
const bool pagingEnabled{};
const bool pinchGestureEnabled{true};
const bool scrollsToTop{true};
const bool showsHorizontalScrollIndicator{true};
const bool showsVerticalScrollIndicator{true};
const Float scrollEventThrottle{};
const Float zoomScale{1.0};
const EdgeInsets contentInset{};
const EdgeInsets scrollIndicatorInsets{};
const Float snapToInterval{};
const ScrollViewSnapToAlignment snapToAlignment{};
#pragma mark - DebugStringConvertible
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList getDebugProps() const override;
#endif
};
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ScrollViewShadowNode.h"
#include <react/core/LayoutMetrics.h>
namespace facebook {
namespace react {
const char ScrollViewComponentName[] = "ScrollView";
void ScrollViewShadowNode::updateStateIfNeeded() {
ensureUnsealed();
auto contentBoundingRect = Rect{};
for (const auto &childNode : getLayoutableChildNodes()) {
contentBoundingRect.unionInPlace(childNode->getLayoutMetrics().frame);
}
auto state = getStateData();
if (state.contentBoundingRect != contentBoundingRect) {
state.contentBoundingRect = contentBoundingRect;
setStateData(std::move(state));
}
}
#pragma mark - LayoutableShadowNode
void ScrollViewShadowNode::layout(LayoutContext layoutContext) {
ConcreteViewShadowNode::layout(layoutContext);
updateStateIfNeeded();
}
Transform ScrollViewShadowNode::getTransform() const {
auto transform = ConcreteViewShadowNode::getTransform();
auto contentOffset = getStateData().contentOffset;
return transform *
Transform::Translate(-contentOffset.x, -contentOffset.y, 0);
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <react/components/scrollview/ScrollViewEventEmitter.h>
#include <react/components/scrollview/ScrollViewProps.h>
#include <react/components/scrollview/ScrollViewState.h>
#include <react/components/view/ConcreteViewShadowNode.h>
#include <react/core/LayoutContext.h>
namespace facebook {
namespace react {
extern const char ScrollViewComponentName[];
/*
* `ShadowNode` for <ScrollView> component.
*/
class ScrollViewShadowNode final : public ConcreteViewShadowNode<
ScrollViewComponentName,
ScrollViewProps,
ScrollViewEventEmitter,
ScrollViewState> {
public:
using ConcreteViewShadowNode::ConcreteViewShadowNode;
#pragma mark - LayoutableShadowNode
void layout(LayoutContext layoutContext) override;
Transform getTransform() const override;
private:
void updateStateIfNeeded();
};
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "ScrollViewState.h"
namespace facebook {
namespace react {
Size ScrollViewState::getContentSize() const {
return Size{contentBoundingRect.getMaxX(), contentBoundingRect.getMaxY()};
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <react/graphics/Geometry.h>
#include <folly/dynamic.h>
namespace facebook {
namespace react {
/*
* State for <ScrollView> component.
*/
class ScrollViewState final {
public:
Point contentOffset;
Rect contentBoundingRect;
/*
* Returns size of scrollable area.
*/
Size getContentSize() const;
#ifdef ANDROID
ScrollViewState() = default;
ScrollViewState(ScrollViewState const &previousState, folly::dynamic data)
: contentOffset({(Float)data["contentOffsetLeft"].getDouble(),
(Float)data["contentOffsetTop"].getDouble()}),
contentBoundingRect({}){};
folly::dynamic getDynamic() const {
return folly::dynamic::object("contentOffsetLeft", contentOffset.x)(
"contentOffsetTop", contentOffset.y);
};
#endif
};
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,107 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* 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 <folly/dynamic.h>
#include <react/components/scrollview/primitives.h>
namespace facebook {
namespace react {
inline void fromRawValue(
const RawValue &value,
ScrollViewSnapToAlignment &result) {
auto string = (std::string)value;
if (string == "start") {
result = ScrollViewSnapToAlignment::Start;
return;
}
if (string == "center") {
result = ScrollViewSnapToAlignment::Center;
return;
}
if (string == "end") {
result = ScrollViewSnapToAlignment::End;
return;
}
abort();
}
inline void fromRawValue(
const RawValue &value,
ScrollViewIndicatorStyle &result) {
auto string = (std::string)value;
if (string == "default") {
result = ScrollViewIndicatorStyle::Default;
return;
}
if (string == "black") {
result = ScrollViewIndicatorStyle::Black;
return;
}
if (string == "white") {
result = ScrollViewIndicatorStyle::White;
return;
}
abort();
}
inline void fromRawValue(
const RawValue &value,
ScrollViewKeyboardDismissMode &result) {
auto string = (std::string)value;
if (string == "none") {
result = ScrollViewKeyboardDismissMode::None;
return;
}
if (string == "on-drag") {
result = ScrollViewKeyboardDismissMode::OnDrag;
return;
}
if (string == "interactive") {
result = ScrollViewKeyboardDismissMode::Interactive;
return;
}
abort();
}
inline std::string toString(const ScrollViewSnapToAlignment &value) {
switch (value) {
case ScrollViewSnapToAlignment::Start:
return "start";
case ScrollViewSnapToAlignment::Center:
return "center";
case ScrollViewSnapToAlignment::End:
return "end";
}
}
inline std::string toString(const ScrollViewIndicatorStyle &value) {
switch (value) {
case ScrollViewIndicatorStyle::Default:
return "default";
case ScrollViewIndicatorStyle::Black:
return "black";
case ScrollViewIndicatorStyle::White:
return "white";
}
}
inline std::string toString(const ScrollViewKeyboardDismissMode &value) {
switch (value) {
case ScrollViewKeyboardDismissMode::None:
return "none";
case ScrollViewKeyboardDismissMode::OnDrag:
return "on-drag";
case ScrollViewKeyboardDismissMode::Interactive:
return "interactive";
}
}
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,20 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
namespace facebook {
namespace react {
enum class ScrollViewSnapToAlignment { Start, Center, End };
enum class ScrollViewIndicatorStyle { Default, Black, White };
enum class ScrollViewKeyboardDismissMode { None, OnDrag, Interactive };
} // namespace react
} // namespace facebook

View File

@ -0,0 +1,14 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <memory>
#include <gtest/gtest.h>
TEST(ScrollViewTest, testSomething) {
// TODO
}