mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-06 22:37:14 +08:00
Add inferfaceOnly option to CodegenSchema
Summary: In some cases the implementation for native modules are more advanced and we cannot currently generate some of the files. We've decided in these cases to only generate the props + events for now, so this flag `interfaceOnly` will only generate those files 👍
Reviewed By: TheSavior
Differential Revision: D14295980
fbshipit-source-id: 1790825143206a84469015e08958bf6f00ffde52
This commit is contained in:
committed by
Facebook Github Bot
parent
b7b8836a7f
commit
f72776e8dc
@@ -43,6 +43,10 @@ fb_native.sh_binary(
|
||||
visibility = ["PUBLIC"],
|
||||
)
|
||||
|
||||
rn_codegen_test(
|
||||
fixture_name = "INTERFACE_ONLY",
|
||||
)
|
||||
|
||||
rn_codegen_test(
|
||||
fixture_name = "BOOLEAN_PROP",
|
||||
)
|
||||
@@ -115,6 +119,7 @@ fb_xplat_cxx_binary(
|
||||
":generated_components-FLOAT_PROPS",
|
||||
":generated_components-IMAGE_PROP",
|
||||
":generated_components-INTEGER_PROPS",
|
||||
":generated_components-INTERFACE_ONLY",
|
||||
":generated_components-MULTI_NATIVE_PROP",
|
||||
":generated_components-STRING_PROP",
|
||||
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
|
||||
@@ -149,6 +154,7 @@ rn_xplat_cxx_library(
|
||||
":generated_components-FLOAT_PROPS",
|
||||
":generated_components-IMAGE_PROP",
|
||||
":generated_components-INTEGER_PROPS",
|
||||
":generated_components-INTERFACE_ONLY",
|
||||
":generated_components-MULTI_NATIVE_PROP",
|
||||
":generated_components-STRING_PROP",
|
||||
":generated_components-TWO_COMPONENTS_DIFFERENT_FILES",
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
#import <react/components/INTERFACE_ONLY/ComponentDescriptors.h>
|
||||
#import <react/components/BOOLEAN_PROP/ComponentDescriptors.h>
|
||||
#import <react/components/STRING_PROP/ComponentDescriptors.h>
|
||||
#import <react/components/INTEGER_PROPS/ComponentDescriptors.h>
|
||||
|
||||
@@ -87,6 +87,7 @@ export type EventTypeShape = $ReadOnly<{|
|
||||
|}>;
|
||||
|
||||
export type ComponentShape = $ReadOnly<{|
|
||||
interfaceOnly?: boolean,
|
||||
extendsProps: $ReadOnlyArray<{|
|
||||
type: 'ReactNativeBuiltInType',
|
||||
knownTypeName: 'ReactNativeCoreViewProps',
|
||||
|
||||
@@ -55,6 +55,9 @@ module.exports = {
|
||||
|
||||
return Object.keys(components)
|
||||
.map(componentName => {
|
||||
if (components[componentName].interfaceOnly === true) {
|
||||
return;
|
||||
}
|
||||
return componentTemplate.replace(/::_CLASSNAME_::/g, componentName);
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
@@ -52,6 +52,9 @@ module.exports = {
|
||||
|
||||
return Object.keys(components)
|
||||
.map(componentName => {
|
||||
if (components[componentName].interfaceOnly === true) {
|
||||
return;
|
||||
}
|
||||
const replacedTemplate = componentTemplate.replace(
|
||||
/::_CLASSNAME_::/g,
|
||||
componentName,
|
||||
|
||||
@@ -65,6 +65,10 @@ module.exports = {
|
||||
return Object.keys(components)
|
||||
.map(componentName => {
|
||||
const component = components[componentName];
|
||||
if (component.interfaceOnly === true) {
|
||||
return;
|
||||
}
|
||||
|
||||
const hasEvents = component.events.length > 0;
|
||||
|
||||
if (hasEvents) {
|
||||
|
||||
@@ -12,6 +12,54 @@
|
||||
|
||||
import type {SchemaType} from '../../CodegenSchema.js';
|
||||
|
||||
const INTERFACE_ONLY: SchemaType = {
|
||||
modules: {
|
||||
Switch: {
|
||||
components: {
|
||||
InterfaceOnlyComponent: {
|
||||
interfaceOnly: true,
|
||||
extendsProps: [
|
||||
{
|
||||
type: 'ReactNativeBuiltInType',
|
||||
knownTypeName: 'ReactNativeCoreViewProps',
|
||||
},
|
||||
],
|
||||
events: [
|
||||
{
|
||||
name: 'onChange',
|
||||
optional: true,
|
||||
bubblingType: 'bubble',
|
||||
typeAnnotation: {
|
||||
type: 'EventTypeAnnotation',
|
||||
argument: {
|
||||
type: 'ObjectTypeAnnotation',
|
||||
properties: [
|
||||
{
|
||||
type: 'BooleanTypeAnnotation',
|
||||
name: 'value',
|
||||
optional: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
props: [
|
||||
{
|
||||
name: 'accessibilityHint',
|
||||
optional: true,
|
||||
typeAnnotation: {
|
||||
type: 'StringTypeAnnotation',
|
||||
default: '',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const BOOLEAN_PROP: SchemaType = {
|
||||
modules: {
|
||||
Switch: {
|
||||
@@ -580,6 +628,7 @@ const TWO_COMPONENTS_DIFFERENT_FILES: SchemaType = {
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
INTERFACE_ONLY,
|
||||
BOOLEAN_PROP,
|
||||
STRING_PROP,
|
||||
INTEGER_PROPS,
|
||||
|
||||
@@ -212,6 +212,35 @@ namespace react {
|
||||
|
||||
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateEventEmitterCpp can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"EventEmitters.cpp" => "
|
||||
/**
|
||||
* 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/INTERFACE_ONLY/EventEmitters.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
void InterfaceOnlyComponentEventEmitter::onChange(InterfaceOnlyComponentOnChangeStruct event) const {
|
||||
dispatchEvent(\\"change\\", [event=std::move(event)](jsi::Runtime &runtime) {
|
||||
auto payload = jsi::Object(runtime);
|
||||
payload.setProperty(runtime, \\"value\\", event.value);
|
||||
return payload;
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
|
||||
@@ -223,6 +223,39 @@ namespace react {
|
||||
|
||||
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateEventEmitterH can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"EventEmitters.h" => "
|
||||
/**
|
||||
* 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 {
|
||||
|
||||
struct InterfaceOnlyComponentOnChangeStruct {
|
||||
bool value;
|
||||
};
|
||||
|
||||
class InterfaceOnlyComponentEventEmitter : public ViewEventEmitter {
|
||||
public:
|
||||
using ViewEventEmitter::ViewEventEmitter;
|
||||
|
||||
void onChange(InterfaceOnlyComponentOnChangeStruct value) const;
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
|
||||
@@ -239,6 +239,35 @@ progress3(convertRawProp(rawProps, \\"progress3\\", sourceProps.progress3, progr
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GeneratePropsCpp can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"Props.cpp" => "
|
||||
/**
|
||||
* 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/INTERFACE_ONLY/Props.h>
|
||||
#include <react/core/propsConversions.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
InterfaceOnlyComponentProps::InterfaceOnlyComponentProps(
|
||||
const InterfaceOnlyComponentProps &sourceProps,
|
||||
const RawProps &rawProps): ViewProps(sourceProps, rawProps),
|
||||
|
||||
accessibilityHint(convertRawProp(rawProps, \\"accessibilityHint\\", sourceProps.accessibilityHint, accessibilityHint))
|
||||
{}
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GeneratePropsCpp can generate fixture MULTI_NATIVE_PROP 1`] = `
|
||||
Map {
|
||||
"Props.cpp" => "
|
||||
|
||||
@@ -274,6 +274,37 @@ const int progress3{10};
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GeneratePropsH can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"Props.h" => "
|
||||
/**
|
||||
* 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/view/ViewProps.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
class InterfaceOnlyComponentProps final : public ViewProps {
|
||||
public:
|
||||
InterfaceOnlyComponentProps() = default;
|
||||
InterfaceOnlyComponentProps(const InterfaceOnlyComponentProps &sourceProps, const RawProps &rawProps);
|
||||
|
||||
#pragma mark - Props
|
||||
|
||||
const std::string accessibilityHint{\\"\\"};
|
||||
};
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GeneratePropsH can generate fixture MULTI_NATIVE_PROP 1`] = `
|
||||
Map {
|
||||
"Props.h" => "
|
||||
|
||||
@@ -178,6 +178,29 @@ namespace react {
|
||||
|
||||
extern const char IntegerPropNativeComponentComponentName[] = \\"IntegerPropNativeComponent\\";
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateShadowNodeCpp can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"ShadowNodes.cpp" => "
|
||||
/**
|
||||
* 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/INTERFACE_ONLY/ShadowNodes.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
|
||||
@@ -262,6 +262,32 @@ using IntegerPropNativeComponentShadowNode = ConcreteViewShadowNode<
|
||||
IntegerPropNativeComponentComponentName,
|
||||
IntegerPropNativeComponentProps>;
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateShadowNodeH can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"ShadowNodes.h" => "
|
||||
/**
|
||||
* 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/INTERFACE_ONLY/Props.h>
|
||||
#include <react/components/view/ConcreteViewShadowNode.h>
|
||||
|
||||
namespace facebook {
|
||||
namespace react {
|
||||
|
||||
|
||||
|
||||
} // namespace react
|
||||
} // namespace facebook
|
||||
",
|
||||
|
||||
@@ -310,6 +310,50 @@ ReactNativeViewConfigRegistry.register(
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateViewConfigJs can generate fixture INTERFACE_ONLY 1`] = `
|
||||
Map {
|
||||
"ViewConfigs.js" => "
|
||||
/**
|
||||
* 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';
|
||||
|
||||
const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
|
||||
const ReactNativeViewConfigRegistry = require('ReactNativeViewConfigRegistry');
|
||||
|
||||
const InterfaceOnlyComponentViewConfig = {
|
||||
uiViewClassName: 'InterfaceOnlyComponent',
|
||||
|
||||
bubblingEventTypes: {
|
||||
onChange: {
|
||||
phasedRegistrationNames: {
|
||||
captured: 'onChangeCapture',
|
||||
bubbled: 'onChange'
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
validAttributes: {
|
||||
accessibilityHint: true,
|
||||
style: ReactNativeStyleAttributes
|
||||
}
|
||||
};
|
||||
|
||||
ReactNativeViewConfigRegistry.register(
|
||||
'InterfaceOnlyComponent',
|
||||
() => InterfaceOnlyComponentViewConfig,
|
||||
);
|
||||
",
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`GenerateViewConfigJs can generate fixture MULTI_NATIVE_PROP 1`] = `
|
||||
Map {
|
||||
"ViewConfigs.js" => "
|
||||
|
||||
Reference in New Issue
Block a user