Use codegen for Slider props + events

Summary: Use the codegen for the Slider component with the new `inferfaceOnly` option

Reviewed By: TheSavior

Differential Revision: D14295981

fbshipit-source-id: 0482572892fbcffada43c7c6fbf17e70546300b8
This commit is contained in:
Rick Hanlon
2019-03-05 11:48:39 -08:00
committed by Facebook Github Bot
parent 9098bc7749
commit d48bd1759e
9 changed files with 227 additions and 174 deletions

View File

@@ -17,7 +17,6 @@ import type {ImageSource} from 'ImageSource';
import type {NativeComponent} from 'ReactNative';
import type {SyntheticEvent} from 'CoreEventTypes';
import type {ViewProps} from 'ViewPropTypes';
import type {ViewStyleProp} from 'StyleSheet';
type Event = SyntheticEvent<
$ReadOnly<{|

View File

@@ -0,0 +1,218 @@
/**
* 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.
*
* @format
* @flow
*/
'use strict';
import type {SchemaType} from '../../../packages/react-native-codegen/src/CodegenSchema.js';
const SliderSchema: SchemaType = {
modules: {
SliderSchema: {
components: {
Slider: {
interfaceOnly: true,
extendsProps: [
{
type: 'ReactNativeBuiltInType',
knownTypeName: 'ReactNativeCoreViewProps',
},
],
events: [
{
name: 'onChange',
optional: true,
bubblingType: 'bubble',
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: {
type: 'ObjectTypeAnnotation',
properties: [
{
type: 'FloatTypeAnnotation',
name: 'value',
optional: false,
},
{
type: 'BooleanTypeAnnotation',
name: 'fromUser',
optional: false,
},
],
},
},
},
{
name: 'onSlidingComplete',
optional: true,
bubblingType: 'bubble',
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: {
type: 'ObjectTypeAnnotation',
properties: [
{
type: 'FloatTypeAnnotation',
name: 'value',
optional: false,
},
{
type: 'BooleanTypeAnnotation',
name: 'fromUser',
optional: false,
},
],
},
},
},
{
name: 'onValueChange',
optional: true,
bubblingType: 'bubble',
typeAnnotation: {
type: 'EventTypeAnnotation',
argument: {
type: 'ObjectTypeAnnotation',
properties: [
{
type: 'FloatTypeAnnotation',
name: 'value',
optional: false,
},
{
type: 'BooleanTypeAnnotation',
name: 'fromUser',
optional: false,
},
],
},
},
},
],
props: [
{
name: 'disabled',
optional: true,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
default: false,
},
},
{
name: 'enabled',
optional: true,
typeAnnotation: {
type: 'BooleanTypeAnnotation',
default: false,
},
},
{
name: 'maximumTrackImage',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ImageSourcePrimitive',
},
},
{
name: 'maximumTrackTintColor',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ColorPrimitive',
},
},
{
name: 'maximumValue',
optional: true,
typeAnnotation: {
type: 'FloatTypeAnnotation',
default: 1,
},
},
{
name: 'minimumTrackImage',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ImageSourcePrimitive',
},
},
{
name: 'minimumTrackTintColor',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ColorPrimitive',
},
},
{
name: 'minimumValue',
optional: true,
typeAnnotation: {
type: 'FloatTypeAnnotation',
default: 0,
},
},
{
name: 'step',
optional: true,
typeAnnotation: {
type: 'FloatTypeAnnotation',
default: 0,
},
},
{
name: 'testID',
optional: true,
typeAnnotation: {
type: 'StringTypeAnnotation',
default: '',
},
},
{
name: 'thumbImage',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ImageSourcePrimitive',
},
},
{
name: 'trackImage',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ImageSourcePrimitive',
},
},
{
name: 'thumbTintColor',
optional: true,
typeAnnotation: {
type: 'NativePrimitiveTypeAnnotation',
name: 'ColorPrimitive',
},
},
{
name: 'value',
optional: true,
typeAnnotation: {
type: 'FloatTypeAnnotation',
default: 0,
},
},
],
},
},
},
},
};
module.exports = SliderSchema;

View File

@@ -8,9 +8,9 @@
#import "RCTSliderComponentView.h"
#import <React/RCTImageResponseObserverProxy.h>
#import <react/components/slider/SliderEventEmitter.h>
#import <react/components/rncore/EventEmitters.h>
#import <react/components/rncore/Props.h>
#import <react/components/slider/SliderLocalData.h>
#import <react/components/slider/SliderProps.h>
#import <react/components/slider/SliderShadowNode.h>
#import "MainQueueExecutor.h"
@@ -301,10 +301,12 @@ using namespace facebook::react;
}
if (continuous && _previousValue != value) {
std::dynamic_pointer_cast<const SliderEventEmitter>(_eventEmitter)->onValueChange(value);
std::dynamic_pointer_cast<const SliderEventEmitter>(_eventEmitter)
->onValueChange(SliderOnValueChangeStruct{.value = static_cast<Float>(value)});
}
if (!continuous) {
std::dynamic_pointer_cast<const SliderEventEmitter>(_eventEmitter)->onSlidingComplete(value);
std::dynamic_pointer_cast<const SliderEventEmitter>(_eventEmitter)
->onSlidingComplete(SliderOnSlidingCompleteStruct{.value = static_cast<Float>(value)});
}
_previousValue = value;

View File

@@ -91,6 +91,7 @@ rn_xplat_cxx_library(
react_native_xplat_target("fabric/graphics:graphics"),
react_native_xplat_target("fabric/imagemanager:imagemanager"),
react_native_xplat_target("fabric/uimanager:uimanager"),
"fbsource//xplat/js:generated_components-rncore",
],
)

View File

@@ -1,30 +0,0 @@
/**
* 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 "SliderEventEmitter.h"
namespace facebook {
namespace react {
void SliderEventEmitter::onValueChange(float value) const {
dispatchEvent("valueChange", [value](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "value", value);
return payload;
});
}
void SliderEventEmitter::onSlidingComplete(float value) const {
dispatchEvent("slidingComplete", [value](jsi::Runtime &runtime) {
auto payload = jsi::Object(runtime);
payload.setProperty(runtime, "value", value);
return payload;
});
}
} // namespace react
} // namespace facebook

View File

@@ -1,23 +0,0 @@
/**
* 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/view/ViewEventEmitter.h>
namespace facebook {
namespace react {
class SliderEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
void onValueChange(float value) const;
void onSlidingComplete(float value) const;
};
} // namespace react
} // namespace facebook

View File

@@ -1,70 +0,0 @@
/**
* 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 <react/components/slider/SliderProps.h>
#include <react/components/image/conversions.h>
#include <react/core/propsConversions.h>
namespace facebook {
namespace react {
SliderProps::SliderProps(
const SliderProps &sourceProps,
const RawProps &rawProps)
: ViewProps(sourceProps, rawProps),
value(convertRawProp(rawProps, "value", sourceProps.value, value)),
minimumValue(convertRawProp(
rawProps,
"minimumValue",
sourceProps.minimumValue,
minimumValue)),
maximumValue(convertRawProp(
rawProps,
"maximumValue",
sourceProps.maximumValue,
maximumValue)),
step(convertRawProp(rawProps, "step", sourceProps.step, step)),
disabled(
convertRawProp(rawProps, "disabled", sourceProps.disabled, disabled)),
minimumTrackTintColor(convertRawProp(
rawProps,
"minimumTrackTintColor",
sourceProps.minimumTrackTintColor,
minimumTrackTintColor)),
maximumTrackTintColor(convertRawProp(
rawProps,
"maximumTrackTintColor",
sourceProps.maximumTrackTintColor,
maximumTrackTintColor)),
thumbTintColor(convertRawProp(
rawProps,
"thumbTintColor",
sourceProps.thumbTintColor,
thumbTintColor)),
trackImage(convertRawProp(
rawProps,
"trackImage",
sourceProps.trackImage,
trackImage)),
minimumTrackImage(convertRawProp(
rawProps,
"minimumTrackImage",
sourceProps.minimumTrackImage,
minimumTrackImage)),
maximumTrackImage(convertRawProp(
rawProps,
"maximumTrackImage",
sourceProps.maximumTrackImage,
maximumTrackImage)),
thumbImage(convertRawProp(
rawProps,
"thumbImage",
sourceProps.thumbImage,
thumbImage)) {}
} // namespace react
} // namespace facebook

View File

@@ -1,44 +0,0 @@
/**
* 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/view/ViewProps.h>
#include <react/graphics/Color.h>
#include <react/imagemanager/primitives.h>
namespace facebook {
namespace react {
// TODO (T28334063): Consider for codegen.
class SliderProps final : public ViewProps {
public:
SliderProps() = default;
SliderProps(const SliderProps &sourceProps, const RawProps &rawProps);
#pragma mark - Props
const float value{0};
const float minimumValue{0};
const float maximumValue{1};
const float step{0};
const bool disabled{false};
const SharedColor minimumTrackTintColor{};
const SharedColor maximumTrackTintColor{};
// Android only
const SharedColor thumbTintColor;
// iOS only
const ImageSource trackImage{};
const ImageSource minimumTrackImage{};
const ImageSource maximumTrackImage{};
const ImageSource thumbImage{};
};
} // namespace react
} // namespace facebook

View File

@@ -7,9 +7,9 @@
#pragma once
#include <react/components/slider/SliderEventEmitter.h>
#import <react/components/rncore/EventEmitters.h>
#import <react/components/rncore/Props.h>
#include <react/components/slider/SliderMeasurementsManager.h>
#include <react/components/slider/SliderProps.h>
#include <react/components/view/ConcreteViewShadowNode.h>
#include <react/imagemanager/ImageManager.h>
#include <react/imagemanager/primitives.h>