Skip to content

Commit 0ae5e50

Browse files
genkikondofacebook-github-bot
authored andcommitted
Support mixed props for components
Summary: Changelog: [Changed][General] - Support mixed props for components in codegen Reviewed By: rickhanlonii Differential Revision: D43894460 fbshipit-source-id: e5faf2f83e6829170cdce550e923c3c09ddff0b0
1 parent e5b97f0 commit 0ae5e50

File tree

47 files changed

+949
-4
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+949
-4
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
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+
* @format
8+
* @flow strict-local
9+
*/
10+
11+
import type {ViewProps} from 'react-native/Libraries/Components/View/ViewPropTypes';
12+
import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
13+
import type {HostComponent} from 'react-native/Libraries/Renderer/shims/ReactNativeTypes';
14+
import type {UnsafeMixed} from 'react-native/Libraries/Types/CodegenTypes';
15+
16+
type NativeProps = $ReadOnly<{|
17+
...ViewProps,
18+
19+
// Props
20+
mixedProp?: UnsafeMixed,
21+
|}>;
22+
23+
export default (codegenNativeComponent<NativeProps>(
24+
'MixedPropNativeComponentView',
25+
): HostComponent<NativeProps>);

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateComponentDescriptorH-test.js.snap

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,34 @@ namespace react {
330330
331331
332332
333+
} // namespace react
334+
} // namespace facebook
335+
",
336+
}
337+
`;
338+
339+
exports[`GenerateComponentDescriptorH can generate for 'MixedPropNativeComponent.js' 1`] = `
340+
Object {
341+
"ComponentDescriptors.h": "
342+
/**
343+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
344+
*
345+
* Do not edit this file as changes may cause incorrect behavior and will be lost
346+
* once the code is regenerated.
347+
*
348+
* @generated by codegen project: GenerateComponentDescriptorH.js
349+
*/
350+
351+
#pragma once
352+
353+
#include <react/renderer/components/RNCodegenModuleFixtures/ShadowNodes.h>
354+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
355+
356+
namespace facebook {
357+
namespace react {
358+
359+
using MixedPropNativeComponentViewComponentDescriptor = ConcreteComponentDescriptor<MixedPropNativeComponentViewShadowNode>;
360+
333361
} // namespace react
334362
} // namespace facebook
335363
",

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateComponentHObjCpp-test.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,31 @@ NS_ASSUME_NONNULL_END",
300300
}
301301
`;
302302
303+
exports[`GenerateComponentHObjCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
304+
Object {
305+
"RCTComponentViewHelpers.h": "/**
306+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
307+
*
308+
* Do not edit this file as changes may cause incorrect behavior and will be lost
309+
* once the code is regenerated.
310+
*
311+
* @generated by codegen project: GenerateComponentHObjCpp.js
312+
*/
313+
314+
#import <Foundation/Foundation.h>
315+
#import <React/RCTDefines.h>
316+
#import <React/RCTLog.h>
317+
318+
NS_ASSUME_NONNULL_BEGIN
319+
320+
@protocol RCTMixedPropNativeComponentViewViewProtocol <NSObject>
321+
322+
@end
323+
324+
NS_ASSUME_NONNULL_END",
325+
}
326+
`;
327+
303328
exports[`GenerateComponentHObjCpp can generate for 'MultiNativePropNativeComponent.js' 1`] = `
304329
Object {
305330
"RCTComponentViewHelpers.h": "/**

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterCpp-test.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,31 @@ void InterfaceOnlyNativeComponentViewEventEmitter::onChange(OnChange event) cons
362362
});
363363
}
364364
365+
} // namespace react
366+
} // namespace facebook
367+
",
368+
}
369+
`;
370+
371+
exports[`GenerateEventEmitterCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
372+
Object {
373+
"EventEmitters.cpp": "
374+
/**
375+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
376+
*
377+
* Do not edit this file as changes may cause incorrect behavior and will be lost
378+
* once the code is regenerated.
379+
*
380+
* @generated by codegen project: GenerateEventEmitterCpp.js
381+
*/
382+
383+
#include <react/renderer/components/RNCodegenModuleFixtures/EventEmitters.h>
384+
385+
namespace facebook {
386+
namespace react {
387+
388+
389+
365390
} // namespace react
366391
} // namespace facebook
367392
",

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateEventEmitterH-test.js.snap

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,40 @@ class JSI_EXPORT InterfaceOnlyNativeComponentViewEventEmitter : public ViewEvent
461461
};
462462
463463
void onChange(OnChange value) const;
464+
};
465+
466+
} // namespace react
467+
} // namespace facebook
468+
",
469+
}
470+
`;
471+
472+
exports[`GenerateEventEmitterH can generate for 'MixedPropNativeComponent.js' 1`] = `
473+
Object {
474+
"EventEmitters.h": "
475+
/**
476+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
477+
*
478+
* Do not edit this file as changes may cause incorrect behavior and will be lost
479+
* once the code is regenerated.
480+
*
481+
* @generated by codegen project: GenerateEventEmitterH.js
482+
*/
483+
#pragma once
484+
485+
#include <react/renderer/components/view/ViewEventEmitter.h>
486+
#include <jsi/jsi.h>
487+
488+
namespace facebook {
489+
namespace react {
490+
491+
class JSI_EXPORT MixedPropNativeComponentViewEventEmitter : public ViewEventEmitter {
492+
public:
493+
using ViewEventEmitter::ViewEventEmitter;
494+
495+
496+
497+
464498
};
465499
466500
} // namespace react

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsCpp-test.js.snap

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,39 @@ InterfaceOnlyNativeComponentViewProps::InterfaceOnlyNativeComponentViewProps(
421421
}
422422
`;
423423
424+
exports[`GeneratePropsCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
425+
Object {
426+
"Props.cpp": "
427+
/**
428+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
429+
*
430+
* Do not edit this file as changes may cause incorrect behavior and will be lost
431+
* once the code is regenerated.
432+
*
433+
* @generated by codegen project: GeneratePropsCpp.js
434+
*/
435+
436+
#include <react/renderer/components/RNCodegenModuleFixtures/Props.h>
437+
#include <react/renderer/core/PropsParserContext.h>
438+
#include <react/renderer/core/propsConversions.h>
439+
440+
namespace facebook {
441+
namespace react {
442+
443+
MixedPropNativeComponentViewProps::MixedPropNativeComponentViewProps(
444+
const PropsParserContext &context,
445+
const MixedPropNativeComponentViewProps &sourceProps,
446+
const RawProps &rawProps): ViewProps(context, sourceProps, rawProps),
447+
448+
mixedProp(convertRawProp(context, rawProps, \\"mixedProp\\", sourceProps.mixedProp, {}))
449+
{}
450+
451+
} // namespace react
452+
} // namespace facebook
453+
",
454+
}
455+
`;
456+
424457
exports[`GeneratePropsCpp can generate for 'MultiNativePropNativeComponent.js' 1`] = `
425458
Object {
426459
"Props.cpp": "

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsH-test.js.snap

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,42 @@ class JSI_EXPORT InterfaceOnlyNativeComponentViewProps final : public ViewProps
625625
}
626626
`;
627627
628+
exports[`GeneratePropsH can generate for 'MixedPropNativeComponent.js' 1`] = `
629+
Object {
630+
"Props.h": "
631+
/**
632+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
633+
*
634+
* Do not edit this file as changes may cause incorrect behavior and will be lost
635+
* once the code is regenerated.
636+
*
637+
* @generated by codegen project: GeneratePropsH.js
638+
*/
639+
#pragma once
640+
641+
#include <jsi/jsi.h>
642+
#include <react/renderer/components/view/ViewProps.h>
643+
#include <react/renderer/core/PropsParserContext.h>
644+
645+
namespace facebook {
646+
namespace react {
647+
648+
class JSI_EXPORT MixedPropNativeComponentViewProps final : public ViewProps {
649+
public:
650+
MixedPropNativeComponentViewProps() = default;
651+
MixedPropNativeComponentViewProps(const PropsParserContext& context, const MixedPropNativeComponentViewProps &sourceProps, const RawProps &rawProps);
652+
653+
#pragma mark - Props
654+
655+
folly::dynamic mixedProp{};
656+
};
657+
658+
} // namespace react
659+
} // namespace facebook
660+
",
661+
}
662+
`;
663+
628664
exports[`GeneratePropsH can generate for 'MultiNativePropNativeComponent.js' 1`] = `
629665
Object {
630666
"Props.h": "

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsJavaDelegate-test.js.snap

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,44 @@ public class InterfaceOnlyNativeComponentViewManagerDelegate<T extends View, U e
505505
}
506506
`;
507507
508+
exports[`GeneratePropsJavaDelegate can generate for 'MixedPropNativeComponent.js' 1`] = `
509+
Object {
510+
"java/com/facebook/react/viewmanagers/MixedPropNativeComponentViewManagerDelegate.java": "/**
511+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
512+
*
513+
* Do not edit this file as changes may cause incorrect behavior and will be lost
514+
* once the code is regenerated.
515+
*
516+
* @generated by codegen project: GeneratePropsJavaDelegate.js
517+
*/
518+
519+
package com.facebook.react.viewmanagers;
520+
521+
import android.view.View;
522+
import androidx.annotation.Nullable;
523+
import com.facebook.react.bridge.DynamicFromObject;
524+
import com.facebook.react.uimanager.BaseViewManagerDelegate;
525+
import com.facebook.react.uimanager.BaseViewManagerInterface;
526+
527+
public class MixedPropNativeComponentViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & MixedPropNativeComponentViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
528+
public MixedPropNativeComponentViewManagerDelegate(U viewManager) {
529+
super(viewManager);
530+
}
531+
@Override
532+
public void setProperty(T view, String propName, @Nullable Object value) {
533+
switch (propName) {
534+
case \\"mixedProp\\":
535+
mViewManager.setMixedProp(view, new DynamicFromObject(value));
536+
break;
537+
default:
538+
super.setProperty(view, propName, value);
539+
}
540+
}
541+
}
542+
",
543+
}
544+
`;
545+
508546
exports[`GeneratePropsJavaDelegate can generate for 'MultiNativePropNativeComponent.js' 1`] = `
509547
Object {
510548
"java/com/facebook/react/viewmanagers/MultiNativePropNativeComponentViewManagerDelegate.java": "/**

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GeneratePropsJavaInterface-test.js.snap

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,29 @@ public interface InterfaceOnlyNativeComponentViewManagerInterface<T extends View
296296
}
297297
`;
298298
299+
exports[`GeneratePropsJavaInterface can generate for 'MixedPropNativeComponent.js' 1`] = `
300+
Object {
301+
"java/com/facebook/react/viewmanagers/MixedPropNativeComponentViewManagerInterface.java": "/**
302+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
303+
*
304+
* Do not edit this file as changes may cause incorrect behavior and will be lost
305+
* once the code is regenerated.
306+
*
307+
* @generated by codegen project: GeneratePropsJavaInterface.js
308+
*/
309+
310+
package com.facebook.react.viewmanagers;
311+
312+
import android.view.View;
313+
import com.facebook.react.bridge.Dynamic;
314+
315+
public interface MixedPropNativeComponentViewManagerInterface<T extends View> {
316+
void setMixedProp(T view, Dynamic value);
317+
}
318+
",
319+
}
320+
`;
321+
299322
exports[`GeneratePropsJavaInterface can generate for 'MultiNativePropNativeComponent.js' 1`] = `
300323
Object {
301324
"java/com/facebook/react/viewmanagers/MultiNativePropNativeComponentViewManagerInterface.java": "/**

packages/react-native-codegen/e2e/__tests__/components/__snapshots__/GenerateShadowNodeCpp-test.js.snap

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,31 @@ namespace react {
294294
295295
296296
297+
} // namespace react
298+
} // namespace facebook
299+
",
300+
}
301+
`;
302+
303+
exports[`GenerateShadowNodeCpp can generate for 'MixedPropNativeComponent.js' 1`] = `
304+
Object {
305+
"ShadowNodes.cpp": "
306+
/**
307+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
308+
*
309+
* Do not edit this file as changes may cause incorrect behavior and will be lost
310+
* once the code is regenerated.
311+
*
312+
* @generated by codegen project: GenerateShadowNodeCpp.js
313+
*/
314+
315+
#include <react/renderer/components/RNCodegenModuleFixtures/ShadowNodes.h>
316+
317+
namespace facebook {
318+
namespace react {
319+
320+
extern const char MixedPropNativeComponentViewComponentName[] = \\"MixedPropNativeComponentView\\";
321+
297322
} // namespace react
298323
} // namespace facebook
299324
",

0 commit comments

Comments
 (0)