Skip to content

Commit

Permalink
Support mixed props for components
Browse files Browse the repository at this point in the history
Summary:
Changelog:
[Changed][General] - Support mixed props for components in codegen

Reviewed By: rickhanlonii

Differential Revision: D43894460

fbshipit-source-id: e5faf2f83e6829170cdce550e923c3c09ddff0b0
  • Loading branch information
genkikondo authored and facebook-github-bot committed Mar 19, 2023
1 parent e5b97f0 commit 0ae5e50
Show file tree
Hide file tree
Showing 47 changed files with 949 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Meta Platforms, Inc. and 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 strict-local
*/

import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
import type {UnsafeMixed} from 'react-native/Libraries/Types/CodegenTypes';

type NativeProps = $ReadOnly<{|
...ViewProps,

// Props
mixedProp?: UnsafeMixed,
|}>;

export default (codegenNativeComponent<NativeProps>(
'MixedPropNativeComponentView',
): HostComponent<NativeProps>);
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,34 @@ namespace react {
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateComponentDescriptorH can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"ComponentDescriptors.h": "
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateComponentDescriptorH.js
*/
#pragma once
#include <react/renderer/components/RNCodegenModuleFixtures/ShadowNodes.h>
#include <react/renderer/core/ConcreteComponentDescriptor.h>
namespace facebook {
namespace react {
using MixedPropNativeComponentViewComponentDescriptor = ConcreteComponentDescriptor<MixedPropNativeComponentViewShadowNode>;
} // namespace react
} // namespace facebook
",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,31 @@ NS_ASSUME_NONNULL_END",
}
`;
exports[`GenerateComponentHObjCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"RCTComponentViewHelpers.h": "/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateComponentHObjCpp.js
*/
#import <Foundation/Foundation.h>
#import <React/RCTDefines.h>
#import <React/RCTLog.h>
NS_ASSUME_NONNULL_BEGIN
@protocol RCTMixedPropNativeComponentViewViewProtocol <NSObject>
@end
NS_ASSUME_NONNULL_END",
}
`;
exports[`GenerateComponentHObjCpp can generate for 'MultiNativePropNativeComponent.js' 1`] = `
Object {
"RCTComponentViewHelpers.h": "/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,31 @@ void InterfaceOnlyNativeComponentViewEventEmitter::onChange(OnChange event) cons
});
}
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateEventEmitterCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"EventEmitters.cpp": "
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateEventEmitterCpp.js
*/
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
namespace facebook {
namespace react {
} // namespace react
} // namespace facebook
",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,40 @@ class JSI_EXPORT InterfaceOnlyNativeComponentViewEventEmitter : public ViewEvent
};
void onChange(OnChange value) const;
};
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateEventEmitterH can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"EventEmitters.h": "
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateEventEmitterH.js
*/
#pragma once
#include <react/renderer/components/view/ViewEventEmitter.h>
#include <jsi/jsi.h>
namespace facebook {
namespace react {
class JSI_EXPORT MixedPropNativeComponentViewEventEmitter : public ViewEventEmitter {
public:
using ViewEventEmitter::ViewEventEmitter;
};
} // namespace react
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,39 @@ InterfaceOnlyNativeComponentViewProps::InterfaceOnlyNativeComponentViewProps(
}
`;
exports[`GeneratePropsCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"Props.cpp": "
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsCpp.js
*/
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
#include <react/renderer/core/PropsParserContext.h>
#include <react/renderer/core/propsConversions.h>
namespace facebook {
namespace react {
MixedPropNativeComponentViewProps::MixedPropNativeComponentViewProps(
const PropsParserContext &context,
const MixedPropNativeComponentViewProps &sourceProps,
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
mixedProp(convertRawProp(context, rawProps, \\"mixedProp\\", sourceProps.mixedProp, {}))
{}
} // namespace react
} // namespace facebook
",
}
`;
exports[`GeneratePropsCpp can generate for 'MultiNativePropNativeComponent.js' 1`] = `
Object {
"Props.cpp": "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,42 @@ class JSI_EXPORT InterfaceOnlyNativeComponentViewProps final : public ViewProps
}
`;
exports[`GeneratePropsH can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"Props.h": "
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsH.js
*/
#pragma once
#include <jsi/jsi.h>
#include <react/renderer/components/view/ViewProps.h>
#include <react/renderer/core/PropsParserContext.h>
namespace facebook {
namespace react {
class JSI_EXPORT MixedPropNativeComponentViewProps final : public ViewProps {
public:
MixedPropNativeComponentViewProps() = default;
MixedPropNativeComponentViewProps(const PropsParserContext& context, const MixedPropNativeComponentViewProps &sourceProps, const RawProps &rawProps);
#pragma mark - Props
folly::dynamic mixedProp{};
};
} // namespace react
} // namespace facebook
",
}
`;
exports[`GeneratePropsH can generate for 'MultiNativePropNativeComponent.js' 1`] = `
Object {
"Props.h": "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,44 @@ public class InterfaceOnlyNativeComponentViewManagerDelegate<T extends View, U e
}
`;
exports[`GeneratePropsJavaDelegate can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"java/com/facebook/react/viewmanagers/MixedPropNativeComponentViewManagerDelegate.java": "/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/
package com.facebook.react.viewmanagers;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.DynamicFromObject;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
public class MixedPropNativeComponentViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & MixedPropNativeComponentViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public MixedPropNativeComponentViewManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case \\"mixedProp\\":
mViewManager.setMixedProp(view, new DynamicFromObject(value));
break;
default:
super.setProperty(view, propName, value);
}
}
}
",
}
`;
exports[`GeneratePropsJavaDelegate can generate for 'MultiNativePropNativeComponent.js' 1`] = `
Object {
"java/com/facebook/react/viewmanagers/MultiNativePropNativeComponentViewManagerDelegate.java": "/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,29 @@ public interface InterfaceOnlyNativeComponentViewManagerInterface<T extends View
}
`;
exports[`GeneratePropsJavaInterface can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"java/com/facebook/react/viewmanagers/MixedPropNativeComponentViewManagerInterface.java": "/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/
package com.facebook.react.viewmanagers;
import android.view.View;
import com.facebook.react.bridge.Dynamic;
public interface MixedPropNativeComponentViewManagerInterface<T extends View> {
void setMixedProp(T view, Dynamic value);
}
",
}
`;
exports[`GeneratePropsJavaInterface can generate for 'MultiNativePropNativeComponent.js' 1`] = `
Object {
"java/com/facebook/react/viewmanagers/MultiNativePropNativeComponentViewManagerInterface.java": "/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,31 @@ namespace react {
} // namespace react
} // namespace facebook
",
}
`;
exports[`GenerateShadowNodeCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
Object {
"ShadowNodes.cpp": "
/**
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
*
* Do not edit this file as changes may cause incorrect behavior and will be lost
* once the code is regenerated.
*
* @generated by codegen project: GenerateShadowNodeCpp.js
*/
#include <react/renderer/components/RNCodegenModuleFixtures/ShadowNodes.h>
namespace facebook {
namespace react {
extern const char MixedPropNativeComponentViewComponentName[] = \\"MixedPropNativeComponentView\\";
} // namespace react
} // namespace facebook
",
Expand Down
Loading

0 comments on commit 0ae5e50

Please sign in to comment.