diff --git a/.gitattributes b/.gitattributes index c7871284c0a..88b22c4a70f 100644 --- a/.gitattributes +++ b/.gitattributes @@ -11,6 +11,7 @@ # Spec Codegen uses LF *Spec.g.h eol=lf +/vnext/codegen/** eol=lf # Force Visual Studio project files (mostly XML) to CRLF # This helps avoid conflict which occurs when Xmarian/Mac contributors with AutoCRLF=input (or off) diff --git a/change/@react-native-windows-codegen-8bf5b93f-6631-4c78-9860-a9e27b71521e.json b/change/@react-native-windows-codegen-8bf5b93f-6631-4c78-9860-a9e27b71521e.json new file mode 100644 index 00000000000..b7d086dafbf --- /dev/null +++ b/change/@react-native-windows-codegen-8bf5b93f-6631-4c78-9860-a9e27b71521e.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Hook up view component codegen", + "packageName": "@react-native-windows/codegen", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/change/@rnw-scripts-format-files-04311b1d-6be6-4a29-a7ad-193f9d1481e8.json b/change/@rnw-scripts-format-files-04311b1d-6be6-4a29-a7ad-193f9d1481e8.json new file mode 100644 index 00000000000..800a49e988d --- /dev/null +++ b/change/@rnw-scripts-format-files-04311b1d-6be6-4a29-a7ad-193f9d1481e8.json @@ -0,0 +1,7 @@ +{ + "type": "patch", + "comment": "Dont format files in codegen", + "packageName": "@rnw-scripts/format-files", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/change/react-native-windows-5b852b93-ed97-49c0-a263-a649a03c12fa.json b/change/react-native-windows-5b852b93-ed97-49c0-a263-a649a03c12fa.json new file mode 100644 index 00000000000..a0d2263a283 --- /dev/null +++ b/change/react-native-windows-5b852b93-ed97-49c0-a263-a649a03c12fa.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Hook up view component codegen", + "packageName": "react-native-windows", + "email": "30809111+acoates-ms@users.noreply.github.com", + "dependentChangeType": "patch" +} diff --git a/packages/@react-native-windows/codegen/src/Cli.ts b/packages/@react-native-windows/codegen/src/Cli.ts index bdaff3e4455..ecd59d9c269 100644 --- a/packages/@react-native-windows/codegen/src/Cli.ts +++ b/packages/@react-native-windows/codegen/src/Cli.ts @@ -33,6 +33,11 @@ const argv = yargs.options({ describe: 'C++/C# Namespace to put generated native modules in', default: 'MyNamespace', }, + libraryName: { + type: 'string', + required: true, + describe: 'Used for part of the path generated within the codegen dir', + }, }).argv; import {SchemaType} from 'react-native-tscodegen'; @@ -141,7 +146,14 @@ function generate( ): boolean { schemaValidator.validate(schema); - const generatedFiles = []; + const componentOutputdir = path.join( + outputDirectory, + 'react/components', + libraryName, + ); + + const generatedModuleFiles = []; + const generatedComponentFiles = []; /* for (const name of generators) { for (const generator of GENERATORS[name]) { @@ -151,16 +163,50 @@ function generate( */ const generateNM2 = createNM2Generator({namespace: argv.namespace}); + const generatorPropsH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsH') + .generate; + const generatorPropsCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GeneratePropsCPP') + .generate; + const generatorShadowNodeH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeH') + .generate; + const generatorShadowNodeCPP = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateShadowNodeCPP') + .generate; + const generatorComponentDescriptorH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateComponentDescriptorH') + .generate; + const generatorEventEmitterH = require('react-native-tscodegen/lib/rncodegen/src/generators/components/GenerateEventEmitterH') + .generate; + + generatedModuleFiles.push( + ...generateNM2(libraryName, schema, moduleSpecName), + ); - generatedFiles.push(...generateNM2(libraryName, schema, moduleSpecName)); + generatedComponentFiles.push( + ...generatorPropsH(libraryName, schema, moduleSpecName), + ...generatorPropsCPP(libraryName, schema, moduleSpecName), + ...generatorShadowNodeH(libraryName, schema, moduleSpecName), + ...generatorShadowNodeCPP(libraryName, schema, moduleSpecName), + ...generatorComponentDescriptorH(libraryName, schema, moduleSpecName), + ...generatorEventEmitterH(libraryName, schema, moduleSpecName), + ); - const filesToUpdate = new Map([...generatedFiles]); + const moduleFilesToUpdate = new Map([ + ...generatedModuleFiles, + ]); + const componentFilesToUpdate = new Map([ + ...generatedComponentFiles, + ]); if (test === true) { - return checkFilesForChanges(filesToUpdate, outputDirectory); + return ( + checkFilesForChanges(moduleFilesToUpdate, outputDirectory) && + checkFilesForChanges(componentFilesToUpdate, componentOutputdir) + ); } - return writeMapToFiles(filesToUpdate, outputDirectory); + return ( + writeMapToFiles(moduleFilesToUpdate, outputDirectory) && + writeMapToFiles(componentFilesToUpdate, componentOutputdir) + ); } if ((argv.file && argv.files) || (!argv.file && !argv.files)) { @@ -175,7 +221,7 @@ if (argv.file) { schema = combineSchemas(globby.sync(argv.files as string[])); } -const libraryName = 'libraryName'; +const libraryName = argv.libraryName; const moduleSpecName = 'moduleSpecName'; const outputDirectory = 'codegen'; generate( diff --git a/packages/@react-native-windows/codegen/src/generators/GenerateNM2.ts b/packages/@react-native-windows/codegen/src/generators/GenerateNM2.ts index 479486c0937..7341db0586a 100644 --- a/packages/@react-native-windows/codegen/src/generators/GenerateNM2.ts +++ b/packages/@react-native-windows/codegen/src/generators/GenerateNM2.ts @@ -314,32 +314,30 @@ export function createNM2Generator({namespace}: {namespace: string}) { const files = new Map(); const nativeModules = Object.keys(schema.modules) - .map(moduleName => { - const modules = schema.modules[moduleName].nativeModules; - if (!modules) { - throw new Error('modules does not exist'); - } - - return modules; - }) + .map(moduleName => schema.modules[moduleName].nativeModules) .filter(Boolean) .reduce((acc, components) => Object.assign(acc, components), {}); - Object.keys(nativeModules).forEach(name => { - console.log(`Generating Native${name}Spec.g.h`); - const {properties} = nativeModules[name]; - const traversedProperties = renderProperties(properties, false); - const traversedPropertyTuples = renderProperties(properties, true); - - files.set( - `Native${name}Spec.g.h`, - moduleTemplate - .replace(/::_MODULE_PROPERTIES_TUPLE_::/g, traversedPropertyTuples) - .replace(/::_MODULE_PROPERTIES_SPEC_ERRORS_::/g, traversedProperties) - .replace(/::_MODULE_NAME_::/g, name) - .replace(/::_NAMESPACE_::/g, namespace), - ); - }); + if (nativeModules) { + Object.keys(nativeModules).forEach(name => { + console.log(`Generating Native${name}Spec.g.h`); + const {properties} = nativeModules[name]; + const traversedProperties = renderProperties(properties, false); + const traversedPropertyTuples = renderProperties(properties, true); + + files.set( + `Native${name}Spec.g.h`, + moduleTemplate + .replace(/::_MODULE_PROPERTIES_TUPLE_::/g, traversedPropertyTuples) + .replace( + /::_MODULE_PROPERTIES_SPEC_ERRORS_::/g, + traversedProperties, + ) + .replace(/::_MODULE_NAME_::/g, name) + .replace(/::_NAMESPACE_::/g, namespace), + ); + }); + } return files; }; diff --git a/vnext/Microsoft.ReactNative/Fabric/ActivityIndicatorComponentView.cpp b/vnext/Microsoft.ReactNative/Fabric/ActivityIndicatorComponentView.cpp new file mode 100644 index 00000000000..6e414fd702e --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/ActivityIndicatorComponentView.cpp @@ -0,0 +1,82 @@ + +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#include "ActivityIndicatorComponentView.h" + +#include +#include + +#include + +namespace Microsoft::ReactNative { + +ActivityIndicatorComponentView::ActivityIndicatorComponentView() : m_element(xaml::Controls::ProgressRing()) { + static auto const defaultProps = std::make_shared(); + m_props = defaultProps; +} + +std::vector +ActivityIndicatorComponentView::supplementalComponentDescriptorProviders() noexcept { + return {}; +} + +void ActivityIndicatorComponentView::mountChildComponentView( + const IComponentView &childComponentView, + uint32_t index) noexcept { + assert(false); +} + +void ActivityIndicatorComponentView::unmountChildComponentView( + const IComponentView &childComponentView, + uint32_t index) noexcept { + assert(false); +} + +void ActivityIndicatorComponentView::updateProps( + facebook::react::Props::Shared const &props, + facebook::react::Props::Shared const &oldProps) noexcept { + const auto &oldActivityProps = *std::static_pointer_cast(m_props); + const auto &newActivityProps = *std::static_pointer_cast(props); + + if (oldActivityProps.animating != newActivityProps.animating) { + m_element.IsActive(newActivityProps.animating); + } + + if (oldActivityProps.color != newActivityProps.color) { + m_element.Foreground(SolidColorBrushFrom(newActivityProps.color)); + } + + m_props = std::static_pointer_cast(props); +} + +void ActivityIndicatorComponentView::updateState( + facebook::react::State::Shared const &state, + facebook::react::State::Shared const &oldState) noexcept {} +void ActivityIndicatorComponentView::updateLayoutMetrics( + facebook::react::LayoutMetrics const &layoutMetrics, + facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept { + // Set Position & Size Properties + + m_layoutMetrics = layoutMetrics; + + winrt::Microsoft::ReactNative::ViewPanel::SetLeft(m_element, layoutMetrics.frame.origin.x); + winrt::Microsoft::ReactNative::ViewPanel::SetTop(m_element, layoutMetrics.frame.origin.y); + + m_element.Width(layoutMetrics.frame.size.width); + m_element.Height(layoutMetrics.frame.size.height); +} +void ActivityIndicatorComponentView::finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept {} +void ActivityIndicatorComponentView::prepareForRecycle() noexcept {} +facebook::react::SharedProps ActivityIndicatorComponentView::props() noexcept { + assert(false); + return {}; +} + +const xaml::FrameworkElement ActivityIndicatorComponentView::Element() const noexcept { + return m_element; +} + +} // namespace Microsoft::ReactNative diff --git a/vnext/Microsoft.ReactNative/Fabric/ActivityIndicatorComponentView.h b/vnext/Microsoft.ReactNative/Fabric/ActivityIndicatorComponentView.h new file mode 100644 index 00000000000..36ff07e3fd2 --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/ActivityIndicatorComponentView.h @@ -0,0 +1,46 @@ + +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +#pragma once + +#include "ComponentView.h" + +#include +#include +#include "ViewComponentView.h" + +#pragma warning(push) +#pragma warning(disable : 4244 4305) +#include +#pragma warning(pop) + +namespace Microsoft::ReactNative { + +struct ActivityIndicatorComponentView : BaseComponentView { + ActivityIndicatorComponentView(); + + std::vector supplementalComponentDescriptorProviders() noexcept + override; + void mountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept override; + void unmountChildComponentView(const IComponentView &childComponentView, uint32_t index) noexcept override; + void updateProps(facebook::react::Props::Shared const &props, facebook::react::Props::Shared const &oldProps) noexcept + override; + void updateState(facebook::react::State::Shared const &state, facebook::react::State::Shared const &oldState) noexcept + override; + void updateLayoutMetrics( + facebook::react::LayoutMetrics const &layoutMetrics, + facebook::react::LayoutMetrics const &oldLayoutMetrics) noexcept override; + void finalizeUpdates(RNComponentViewUpdateMask updateMask) noexcept override; + void prepareForRecycle() noexcept override; + facebook::react::SharedProps props() noexcept override; + + const xaml::FrameworkElement Element() const noexcept override; + + private: + facebook::react::SharedViewProps m_props; + facebook::react::LayoutMetrics m_layoutMetrics; + xaml::Controls::ProgressRing m_element; +}; + +} // namespace Microsoft::ReactNative diff --git a/vnext/Microsoft.ReactNative/Fabric/ComponentViewRegistry.cpp b/vnext/Microsoft.ReactNative/Fabric/ComponentViewRegistry.cpp index 1a5099570e9..6628f540b7b 100644 --- a/vnext/Microsoft.ReactNative/Fabric/ComponentViewRegistry.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/ComponentViewRegistry.cpp @@ -10,6 +10,7 @@ #include #pragma warning(pop) +#include #include #include #include @@ -18,6 +19,7 @@ #include #include +#include "ActivityIndicatorComponentView.h" #include "ImageComponentView.h" #include "ParagraphComponentView.h" #include "ScrollViewComponentView.h" @@ -45,6 +47,8 @@ ComponentViewDescriptor const &ComponentViewRegistry::dequeueComponentViewWithCo view = std::make_shared(); } else if (componentHandle == facebook::react::ImageShadowNode::Handle()) { view = std::make_shared(m_context); + } else if (componentHandle == facebook::react::ActivityIndicatorViewShadowNode::Handle()) { + view = std::make_shared(); } else { // Just to keep track of what kinds of shadownodes we are being used verify we know about them here assert( diff --git a/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp b/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp index 529732683e7..63ba9bbb7d8 100644 --- a/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp +++ b/vnext/Microsoft.ReactNative/Fabric/FabricUIManagerModule.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -134,6 +135,8 @@ class AsyncEventBeat final : public facebook::react::EventBeat { //, public face std::shared_ptr sharedProviderRegistry() { static auto providerRegistry = []() -> std::shared_ptr { auto providerRegistry = std::make_shared(); + providerRegistry->add(facebook::react::concreteComponentDescriptorProvider< + facebook::react::ActivityIndicatorViewComponentDescriptor>()); providerRegistry->add( facebook::react::concreteComponentDescriptorProvider()); providerRegistry->add( diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/components/image/conversions.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/image/conversions.h new file mode 100644 index 00000000000..3060c9af922 --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/image/conversions.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ConcreteViewShadowNode.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ConcreteViewShadowNode.h new file mode 100644 index 00000000000..cf160607c26 --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ConcreteViewShadowNode.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ViewEventEmitter.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ViewEventEmitter.h new file mode 100644 index 00000000000..47403ccd40d --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ViewEventEmitter.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ViewProps.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ViewProps.h new file mode 100644 index 00000000000..4b0f3cb0644 --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/components/view/ViewProps.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/core/ConcreteComponentDescriptor.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/core/ConcreteComponentDescriptor.h new file mode 100644 index 00000000000..1513068ffd9 --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/core/ConcreteComponentDescriptor.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/core/propsConversions.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/core/propsConversions.h new file mode 100644 index 00000000000..499d9fcef6b --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/core/propsConversions.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/graphics/Color.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/graphics/Color.h new file mode 100644 index 00000000000..bf77acec34a --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/graphics/Color.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Fabric/platform/react/imagemanager/primitives.h b/vnext/Microsoft.ReactNative/Fabric/platform/react/imagemanager/primitives.h new file mode 100644 index 00000000000..8d330918317 --- /dev/null +++ b/vnext/Microsoft.ReactNative/Fabric/platform/react/imagemanager/primitives.h @@ -0,0 +1,5 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +// RN has some weird include directory redirections..this forwards the include to the right place +#include \ No newline at end of file diff --git a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj index 13790ec574b..75d8ce12cb8 100644 --- a/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj +++ b/vnext/Microsoft.ReactNative/Microsoft.ReactNative.vcxproj @@ -104,6 +104,7 @@ $(ReactNativeWindowsDir)Microsoft.ReactNative\ReactHost; $(ReactNativeWindowsDir)Microsoft.ReactNative\Views; $(ReactNativeWindowsDir); + $(ReactNativeWindowsDir)codegen; $(ReactNativeWindowsDir)Common; $(ReactNativeWindowsDir)include; $(ReactNativeWindowsDir)Shared; @@ -466,6 +467,11 @@ + + $(IntDir)\codegenRnwCoreProps.obj + + + diff --git a/vnext/codegen/.clang-format b/vnext/codegen/.clang-format new file mode 100644 index 00000000000..a43d914ec38 --- /dev/null +++ b/vnext/codegen/.clang-format @@ -0,0 +1,2 @@ +DisableFormat: true +SortIncludes: false \ No newline at end of file diff --git a/vnext/codegen/react/components/rnwcore/ComponentDescriptors.h b/vnext/codegen/react/components/rnwcore/ComponentDescriptors.h new file mode 100644 index 00000000000..9f290d50a3c --- /dev/null +++ b/vnext/codegen/react/components/rnwcore/ComponentDescriptors.h @@ -0,0 +1,30 @@ + +/** + * 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 +#include + +namespace facebook { +namespace react { + +using ActivityIndicatorViewComponentDescriptor = ConcreteComponentDescriptor; +using DatePickerComponentDescriptor = ConcreteComponentDescriptor; +using AndroidDrawerLayoutComponentDescriptor = ConcreteComponentDescriptor; +using RCTMaskedViewComponentDescriptor = ConcreteComponentDescriptor; +using RCTProgressViewComponentDescriptor = ConcreteComponentDescriptor; +using AndroidSwipeRefreshLayoutComponentDescriptor = ConcreteComponentDescriptor; +using PullToRefreshViewComponentDescriptor = ConcreteComponentDescriptor; +using AndroidHorizontalScrollContentViewComponentDescriptor = ConcreteComponentDescriptor; +using RCTSegmentedControlComponentDescriptor = ConcreteComponentDescriptor; +using SwitchComponentDescriptor = ConcreteComponentDescriptor; +using UnimplementedNativeViewComponentDescriptor = ConcreteComponentDescriptor; + +} // namespace react +} // namespace facebook diff --git a/vnext/codegen/react/components/rnwcore/EventEmitters.h b/vnext/codegen/react/components/rnwcore/EventEmitters.h new file mode 100644 index 00000000000..d6ea9166de2 --- /dev/null +++ b/vnext/codegen/react/components/rnwcore/EventEmitters.h @@ -0,0 +1,235 @@ + +/** + * 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 + +namespace facebook { +namespace react { + +class ModalHostViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnRequestClose { + + }; + + struct OnShow { + + }; + + struct OnDismiss { + + }; + + enum class OnOrientationChangeOrientation { + Portrait, + Landscape + }; + + static char const *toString(const OnOrientationChangeOrientation value) { + switch (value) { + case OnOrientationChangeOrientation::Portrait: return "portrait"; + case OnOrientationChangeOrientation::Landscape: return "landscape"; + } + } + + struct OnOrientationChange { + OnOrientationChangeOrientation orientation; + }; + + void onRequestClose(OnRequestClose value) const; + + void onShow(OnShow value) const; + + void onDismiss(OnDismiss value) const; + + void onOrientationChange(OnOrientationChange value) const; +}; +class ActivityIndicatorViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class DatePickerEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnChange { + Float timestamp; + }; + + void onChange(OnChange value) const; +}; +class AndroidDrawerLayoutEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnDrawerSlide { + Float offset; + }; + + struct OnDrawerStateChanged { + int drawerState; + }; + + struct OnDrawerOpen { + + }; + + struct OnDrawerClose { + + }; + + void onDrawerSlide(OnDrawerSlide value) const; + + void onDrawerStateChanged(OnDrawerStateChanged value) const; + + void onDrawerOpen(OnDrawerOpen value) const; + + void onDrawerClose(OnDrawerClose value) const; +}; +class RCTMaskedViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class AndroidProgressBarEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class RCTProgressViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class AndroidSwipeRefreshLayoutEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnRefresh { + + }; + + void onRefresh(OnRefresh value) const; +}; +class PullToRefreshViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnRefresh { + + }; + + void onRefresh(OnRefresh value) const; +}; +class SafeAreaViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class AndroidHorizontalScrollContentViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class RCTSegmentedControlEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnChange { + int value; + int selectedSegmentIndex; + }; + + void onChange(OnChange value) const; +}; +class SliderEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnChange { + double value; + bool fromUser; + }; + + struct OnValueChange { + double value; + bool fromUser; + }; + + struct OnSlidingComplete { + double value; + bool fromUser; + }; + + void onChange(OnChange value) const; + + void onValueChange(OnValueChange value) const; + + void onSlidingComplete(OnSlidingComplete value) const; +}; +class AndroidSwitchEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnChange { + bool value; + }; + + void onChange(OnChange value) const; +}; +class SwitchEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + struct OnChange { + bool value; + }; + + void onChange(OnChange value) const; +}; +class InputAccessoryEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; +class UnimplementedNativeViewEventEmitter : public ViewEventEmitter { + public: + using ViewEventEmitter::ViewEventEmitter; + + + + +}; + +} // namespace react +} // namespace facebook diff --git a/vnext/codegen/react/components/rnwcore/Props.cpp b/vnext/codegen/react/components/rnwcore/Props.cpp new file mode 100644 index 00000000000..89867b16ed2 --- /dev/null +++ b/vnext/codegen/react/components/rnwcore/Props.cpp @@ -0,0 +1,196 @@ + +/** + * 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 +#include +#include + +namespace facebook { +namespace react { + +ModalHostViewProps::ModalHostViewProps( + const ModalHostViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + animationType(convertRawProp(rawProps, "animationType", sourceProps.animationType, {ModalHostViewAnimationType::None})), + presentationStyle(convertRawProp(rawProps, "presentationStyle", sourceProps.presentationStyle, {ModalHostViewPresentationStyle::FullScreen})), + transparent(convertRawProp(rawProps, "transparent", sourceProps.transparent, {false})), + statusBarTranslucent(convertRawProp(rawProps, "statusBarTranslucent", sourceProps.statusBarTranslucent, {false})), + hardwareAccelerated(convertRawProp(rawProps, "hardwareAccelerated", sourceProps.hardwareAccelerated, {false})), + animated(convertRawProp(rawProps, "animated", sourceProps.animated, {false})), + supportedOrientations(convertRawProp(rawProps, "supportedOrientations", sourceProps.supportedOrientations, {static_cast(ModalHostViewSupportedOrientations::Portrait)})), + identifier(convertRawProp(rawProps, "identifier", sourceProps.identifier, {0})) + {} +ActivityIndicatorViewProps::ActivityIndicatorViewProps( + const ActivityIndicatorViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + hidesWhenStopped(convertRawProp(rawProps, "hidesWhenStopped", sourceProps.hidesWhenStopped, {false})), + animating(convertRawProp(rawProps, "animating", sourceProps.animating, {false})), + color(convertRawProp(rawProps, "color", sourceProps.color, {})), + size(convertRawProp(rawProps, "size", sourceProps.size, {ActivityIndicatorViewSize::Small})) + {} +DatePickerProps::DatePickerProps( + const DatePickerProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + date(convertRawProp(rawProps, "date", sourceProps.date, {0.0})), + initialDate(convertRawProp(rawProps, "initialDate", sourceProps.initialDate, {0.0})), + locale(convertRawProp(rawProps, "locale", sourceProps.locale, {})), + maximumDate(convertRawProp(rawProps, "maximumDate", sourceProps.maximumDate, {0.0})), + minimumDate(convertRawProp(rawProps, "minimumDate", sourceProps.minimumDate, {0.0})), + minuteInterval(convertRawProp(rawProps, "minuteInterval", sourceProps.minuteInterval, {DatePickerMinuteInterval::MinuteInterval1})), + mode(convertRawProp(rawProps, "mode", sourceProps.mode, {DatePickerMode::Date})), + timeZoneOffsetInMinutes(convertRawProp(rawProps, "timeZoneOffsetInMinutes", sourceProps.timeZoneOffsetInMinutes, {0.0})) + {} +AndroidDrawerLayoutProps::AndroidDrawerLayoutProps( + const AndroidDrawerLayoutProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + keyboardDismissMode(convertRawProp(rawProps, "keyboardDismissMode", sourceProps.keyboardDismissMode, {AndroidDrawerLayoutKeyboardDismissMode::None})), + drawerBackgroundColor(convertRawProp(rawProps, "drawerBackgroundColor", sourceProps.drawerBackgroundColor, {})), + drawerPosition(convertRawProp(rawProps, "drawerPosition", sourceProps.drawerPosition, {AndroidDrawerLayoutDrawerPosition::Left})), + drawerWidth(convertRawProp(rawProps, "drawerWidth", sourceProps.drawerWidth, {})), + drawerLockMode(convertRawProp(rawProps, "drawerLockMode", sourceProps.drawerLockMode, {AndroidDrawerLayoutDrawerLockMode::Unlocked})), + statusBarBackgroundColor(convertRawProp(rawProps, "statusBarBackgroundColor", sourceProps.statusBarBackgroundColor, {})) + {} +RCTMaskedViewProps::RCTMaskedViewProps( + const RCTMaskedViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps) + + + {} +AndroidProgressBarProps::AndroidProgressBarProps( + const AndroidProgressBarProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + styleAttr(convertRawProp(rawProps, "styleAttr", sourceProps.styleAttr, {})), + typeAttr(convertRawProp(rawProps, "typeAttr", sourceProps.typeAttr, {})), + indeterminate(convertRawProp(rawProps, "indeterminate", sourceProps.indeterminate, {false})), + progress(convertRawProp(rawProps, "progress", sourceProps.progress, {0.0})), + animating(convertRawProp(rawProps, "animating", sourceProps.animating, {true})), + color(convertRawProp(rawProps, "color", sourceProps.color, {})), + testID(convertRawProp(rawProps, "testID", sourceProps.testID, {""})) + {} +RCTProgressViewProps::RCTProgressViewProps( + const RCTProgressViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + progressViewStyle(convertRawProp(rawProps, "progressViewStyle", sourceProps.progressViewStyle, {RCTProgressViewProgressViewStyle::Default})), + progress(convertRawProp(rawProps, "progress", sourceProps.progress, {0.0})), + progressTintColor(convertRawProp(rawProps, "progressTintColor", sourceProps.progressTintColor, {})), + trackTintColor(convertRawProp(rawProps, "trackTintColor", sourceProps.trackTintColor, {})), + progressImage(convertRawProp(rawProps, "progressImage", sourceProps.progressImage, {})), + trackImage(convertRawProp(rawProps, "trackImage", sourceProps.trackImage, {})) + {} +AndroidSwipeRefreshLayoutProps::AndroidSwipeRefreshLayoutProps( + const AndroidSwipeRefreshLayoutProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + enabled(convertRawProp(rawProps, "enabled", sourceProps.enabled, {true})), + colors(convertRawProp(rawProps, "colors", sourceProps.colors, {})), + progressBackgroundColor(convertRawProp(rawProps, "progressBackgroundColor", sourceProps.progressBackgroundColor, {})), + size(convertRawProp(rawProps, "size", sourceProps.size, {AndroidSwipeRefreshLayoutSize::Default})), + progressViewOffset(convertRawProp(rawProps, "progressViewOffset", sourceProps.progressViewOffset, {0.0})), + refreshing(convertRawProp(rawProps, "refreshing", sourceProps.refreshing, {false})) + {} +PullToRefreshViewProps::PullToRefreshViewProps( + const PullToRefreshViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + tintColor(convertRawProp(rawProps, "tintColor", sourceProps.tintColor, {})), + titleColor(convertRawProp(rawProps, "titleColor", sourceProps.titleColor, {})), + title(convertRawProp(rawProps, "title", sourceProps.title, {})), + progressViewOffset(convertRawProp(rawProps, "progressViewOffset", sourceProps.progressViewOffset, {0.0})), + refreshing(convertRawProp(rawProps, "refreshing", sourceProps.refreshing, {false})) + {} +SafeAreaViewProps::SafeAreaViewProps( + const SafeAreaViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + emulateUnlessSupported(convertRawProp(rawProps, "emulateUnlessSupported", sourceProps.emulateUnlessSupported, {false})) + {} +AndroidHorizontalScrollContentViewProps::AndroidHorizontalScrollContentViewProps( + const AndroidHorizontalScrollContentViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps) + + + {} +RCTSegmentedControlProps::RCTSegmentedControlProps( + const RCTSegmentedControlProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + values(convertRawProp(rawProps, "values", sourceProps.values, {})), + selectedIndex(convertRawProp(rawProps, "selectedIndex", sourceProps.selectedIndex, {0})), + enabled(convertRawProp(rawProps, "enabled", sourceProps.enabled, {true})), + tintColor(convertRawProp(rawProps, "tintColor", sourceProps.tintColor, {})), + textColor(convertRawProp(rawProps, "textColor", sourceProps.textColor, {})), + backgroundColor(convertRawProp(rawProps, "backgroundColor", sourceProps.backgroundColor, {})), + momentary(convertRawProp(rawProps, "momentary", sourceProps.momentary, {false})) + {} +SliderProps::SliderProps( + const SliderProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + disabled(convertRawProp(rawProps, "disabled", sourceProps.disabled, {false})), + enabled(convertRawProp(rawProps, "enabled", sourceProps.enabled, {true})), + maximumTrackImage(convertRawProp(rawProps, "maximumTrackImage", sourceProps.maximumTrackImage, {})), + maximumTrackTintColor(convertRawProp(rawProps, "maximumTrackTintColor", sourceProps.maximumTrackTintColor, {})), + maximumValue(convertRawProp(rawProps, "maximumValue", sourceProps.maximumValue, {1.0})), + minimumTrackImage(convertRawProp(rawProps, "minimumTrackImage", sourceProps.minimumTrackImage, {})), + minimumTrackTintColor(convertRawProp(rawProps, "minimumTrackTintColor", sourceProps.minimumTrackTintColor, {})), + minimumValue(convertRawProp(rawProps, "minimumValue", sourceProps.minimumValue, {0.0})), + step(convertRawProp(rawProps, "step", sourceProps.step, {0.0})), + testID(convertRawProp(rawProps, "testID", sourceProps.testID, {""})), + thumbImage(convertRawProp(rawProps, "thumbImage", sourceProps.thumbImage, {})), + thumbTintColor(convertRawProp(rawProps, "thumbTintColor", sourceProps.thumbTintColor, {})), + trackImage(convertRawProp(rawProps, "trackImage", sourceProps.trackImage, {})), + value(convertRawProp(rawProps, "value", sourceProps.value, {0.0})) + {} +AndroidSwitchProps::AndroidSwitchProps( + const AndroidSwitchProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + disabled(convertRawProp(rawProps, "disabled", sourceProps.disabled, {false})), + enabled(convertRawProp(rawProps, "enabled", sourceProps.enabled, {true})), + thumbColor(convertRawProp(rawProps, "thumbColor", sourceProps.thumbColor, {})), + trackColorForFalse(convertRawProp(rawProps, "trackColorForFalse", sourceProps.trackColorForFalse, {})), + trackColorForTrue(convertRawProp(rawProps, "trackColorForTrue", sourceProps.trackColorForTrue, {})), + value(convertRawProp(rawProps, "value", sourceProps.value, {false})), + on(convertRawProp(rawProps, "on", sourceProps.on, {false})), + thumbTintColor(convertRawProp(rawProps, "thumbTintColor", sourceProps.thumbTintColor, {})), + trackTintColor(convertRawProp(rawProps, "trackTintColor", sourceProps.trackTintColor, {})) + {} +SwitchProps::SwitchProps( + const SwitchProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + disabled(convertRawProp(rawProps, "disabled", sourceProps.disabled, {false})), + value(convertRawProp(rawProps, "value", sourceProps.value, {false})), + tintColor(convertRawProp(rawProps, "tintColor", sourceProps.tintColor, {})), + onTintColor(convertRawProp(rawProps, "onTintColor", sourceProps.onTintColor, {})), + thumbTintColor(convertRawProp(rawProps, "thumbTintColor", sourceProps.thumbTintColor, {})), + thumbColor(convertRawProp(rawProps, "thumbColor", sourceProps.thumbColor, {})), + trackColorForFalse(convertRawProp(rawProps, "trackColorForFalse", sourceProps.trackColorForFalse, {})), + trackColorForTrue(convertRawProp(rawProps, "trackColorForTrue", sourceProps.trackColorForTrue, {})) + {} +InputAccessoryProps::InputAccessoryProps( + const InputAccessoryProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + backgroundColor(convertRawProp(rawProps, "backgroundColor", sourceProps.backgroundColor, {})) + {} +UnimplementedNativeViewProps::UnimplementedNativeViewProps( + const UnimplementedNativeViewProps &sourceProps, + const RawProps &rawProps): ViewProps(sourceProps, rawProps), + + name(convertRawProp(rawProps, "name", sourceProps.name, {""})) + {} + +} // namespace react +} // namespace facebook diff --git a/vnext/codegen/react/components/rnwcore/Props.h b/vnext/codegen/react/components/rnwcore/Props.h new file mode 100644 index 00000000000..ee3d35fc69b --- /dev/null +++ b/vnext/codegen/react/components/rnwcore/Props.h @@ -0,0 +1,554 @@ + +/** + * 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 +#include +#include +#include +#include + +namespace facebook { +namespace react { + +enum class ModalHostViewAnimationType { None, Slide, Fade }; + +static inline void fromRawValue(const RawValue &value, ModalHostViewAnimationType &result) { + auto string = (std::string)value; + if (string == "none") { result = ModalHostViewAnimationType::None; return; } + if (string == "slide") { result = ModalHostViewAnimationType::Slide; return; } + if (string == "fade") { result = ModalHostViewAnimationType::Fade; return; } + abort(); +} + +static inline std::string toString(const ModalHostViewAnimationType &value) { + switch (value) { + case ModalHostViewAnimationType::None: return "none"; + case ModalHostViewAnimationType::Slide: return "slide"; + case ModalHostViewAnimationType::Fade: return "fade"; + } +} +enum class ModalHostViewPresentationStyle { FullScreen, PageSheet, FormSheet, OverFullScreen }; + +static inline void fromRawValue(const RawValue &value, ModalHostViewPresentationStyle &result) { + auto string = (std::string)value; + if (string == "fullScreen") { result = ModalHostViewPresentationStyle::FullScreen; return; } + if (string == "pageSheet") { result = ModalHostViewPresentationStyle::PageSheet; return; } + if (string == "formSheet") { result = ModalHostViewPresentationStyle::FormSheet; return; } + if (string == "overFullScreen") { result = ModalHostViewPresentationStyle::OverFullScreen; return; } + abort(); +} + +static inline std::string toString(const ModalHostViewPresentationStyle &value) { + switch (value) { + case ModalHostViewPresentationStyle::FullScreen: return "fullScreen"; + case ModalHostViewPresentationStyle::PageSheet: return "pageSheet"; + case ModalHostViewPresentationStyle::FormSheet: return "formSheet"; + case ModalHostViewPresentationStyle::OverFullScreen: return "overFullScreen"; + } +} +using ModalHostViewSupportedOrientationsMask = uint32_t; + +enum class ModalHostViewSupportedOrientations: ModalHostViewSupportedOrientationsMask { + Portrait = 1 << 0, + PortraitUpsideDown = 1 << 1, + Landscape = 1 << 2, + LandscapeLeft = 1 << 3, + LandscapeRight = 1 << 4 +}; + +constexpr bool operator&( + ModalHostViewSupportedOrientationsMask const lhs, + enum ModalHostViewSupportedOrientations const rhs) { + return lhs & static_cast(rhs); +} + +constexpr ModalHostViewSupportedOrientationsMask operator|( + ModalHostViewSupportedOrientationsMask const lhs, + enum ModalHostViewSupportedOrientations const rhs) { + return lhs | static_cast(rhs); +} + +constexpr void operator|=( + ModalHostViewSupportedOrientationsMask &lhs, + enum ModalHostViewSupportedOrientations const rhs) { + lhs = lhs | static_cast(rhs); +} + +static inline void fromRawValue(const RawValue &value, ModalHostViewSupportedOrientationsMask &result) { + auto items = std::vector{value}; + for (const auto &item : items) { + if (item == "portrait") { + result |= ModalHostViewSupportedOrientations::Portrait; + continue; + } + if (item == "portrait-upside-down") { + result |= ModalHostViewSupportedOrientations::PortraitUpsideDown; + continue; + } + if (item == "landscape") { + result |= ModalHostViewSupportedOrientations::Landscape; + continue; + } + if (item == "landscape-left") { + result |= ModalHostViewSupportedOrientations::LandscapeLeft; + continue; + } + if (item == "landscape-right") { + result |= ModalHostViewSupportedOrientations::LandscapeRight; + continue; + } + abort(); + } +} + +static inline std::string toString(const ModalHostViewSupportedOrientationsMask &value) { + auto result = std::string{}; + auto separator = std::string{", "}; + + if (value & ModalHostViewSupportedOrientations::Portrait) { + result += "portrait" + separator; + } + if (value & ModalHostViewSupportedOrientations::PortraitUpsideDown) { + result += "portrait-upside-down" + separator; + } + if (value & ModalHostViewSupportedOrientations::Landscape) { + result += "landscape" + separator; + } + if (value & ModalHostViewSupportedOrientations::LandscapeLeft) { + result += "landscape-left" + separator; + } + if (value & ModalHostViewSupportedOrientations::LandscapeRight) { + result += "landscape-right" + separator; + } + if (!result.empty()) { + result.erase(result.length() - separator.length()); + } + return result; +} + +class ModalHostViewProps final : public ViewProps { + public: + ModalHostViewProps() = default; + ModalHostViewProps(const ModalHostViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + ModalHostViewAnimationType animationType{ModalHostViewAnimationType::None}; + ModalHostViewPresentationStyle presentationStyle{ModalHostViewPresentationStyle::FullScreen}; + bool transparent{false}; + bool statusBarTranslucent{false}; + bool hardwareAccelerated{false}; + bool animated{false}; + ModalHostViewSupportedOrientationsMask supportedOrientations{static_cast(ModalHostViewSupportedOrientations::Portrait)}; + int identifier{0}; +}; + +enum class ActivityIndicatorViewSize { Small, Large }; + +static inline void fromRawValue(const RawValue &value, ActivityIndicatorViewSize &result) { + auto string = (std::string)value; + if (string == "small") { result = ActivityIndicatorViewSize::Small; return; } + if (string == "large") { result = ActivityIndicatorViewSize::Large; return; } + abort(); +} + +static inline std::string toString(const ActivityIndicatorViewSize &value) { + switch (value) { + case ActivityIndicatorViewSize::Small: return "small"; + case ActivityIndicatorViewSize::Large: return "large"; + } +} + +class ActivityIndicatorViewProps final : public ViewProps { + public: + ActivityIndicatorViewProps() = default; + ActivityIndicatorViewProps(const ActivityIndicatorViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool hidesWhenStopped{false}; + bool animating{false}; + SharedColor color{}; + ActivityIndicatorViewSize size{ActivityIndicatorViewSize::Small}; +}; + +enum class DatePickerMinuteInterval { MinuteInterval1 = 1, MinuteInterval2 = 2, MinuteInterval3 = 3, MinuteInterval4 = 4, MinuteInterval5 = 5, MinuteInterval6 = 6, MinuteInterval10 = 10, MinuteInterval12 = 12, MinuteInterval15 = 15, MinuteInterval20 = 20, MinuteInterval30 = 30 }; + +static inline void fromRawValue(const RawValue &value, DatePickerMinuteInterval &result) { + assert(value.hasType()); + auto integerValue = (int)value; + switch (integerValue) { + case 1: + result = DatePickerMinuteInterval::MinuteInterval1; + return; + case 2: + result = DatePickerMinuteInterval::MinuteInterval2; + return; + case 3: + result = DatePickerMinuteInterval::MinuteInterval3; + return; + case 4: + result = DatePickerMinuteInterval::MinuteInterval4; + return; + case 5: + result = DatePickerMinuteInterval::MinuteInterval5; + return; + case 6: + result = DatePickerMinuteInterval::MinuteInterval6; + return; + case 10: + result = DatePickerMinuteInterval::MinuteInterval10; + return; + case 12: + result = DatePickerMinuteInterval::MinuteInterval12; + return; + case 15: + result = DatePickerMinuteInterval::MinuteInterval15; + return; + case 20: + result = DatePickerMinuteInterval::MinuteInterval20; + return; + case 30: + result = DatePickerMinuteInterval::MinuteInterval30; + return; + } + abort(); +} + +static inline std::string toString(const DatePickerMinuteInterval &value) { + switch (value) { + case DatePickerMinuteInterval::MinuteInterval1: return "1"; + case DatePickerMinuteInterval::MinuteInterval2: return "2"; + case DatePickerMinuteInterval::MinuteInterval3: return "3"; + case DatePickerMinuteInterval::MinuteInterval4: return "4"; + case DatePickerMinuteInterval::MinuteInterval5: return "5"; + case DatePickerMinuteInterval::MinuteInterval6: return "6"; + case DatePickerMinuteInterval::MinuteInterval10: return "10"; + case DatePickerMinuteInterval::MinuteInterval12: return "12"; + case DatePickerMinuteInterval::MinuteInterval15: return "15"; + case DatePickerMinuteInterval::MinuteInterval20: return "20"; + case DatePickerMinuteInterval::MinuteInterval30: return "30"; + } +} +enum class DatePickerMode { Date, Time, Datetime }; + +static inline void fromRawValue(const RawValue &value, DatePickerMode &result) { + auto string = (std::string)value; + if (string == "date") { result = DatePickerMode::Date; return; } + if (string == "time") { result = DatePickerMode::Time; return; } + if (string == "datetime") { result = DatePickerMode::Datetime; return; } + abort(); +} + +static inline std::string toString(const DatePickerMode &value) { + switch (value) { + case DatePickerMode::Date: return "date"; + case DatePickerMode::Time: return "time"; + case DatePickerMode::Datetime: return "datetime"; + } +} + +class DatePickerProps final : public ViewProps { + public: + DatePickerProps() = default; + DatePickerProps(const DatePickerProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + Float date{0.0}; + Float initialDate{0.0}; + std::string locale{}; + Float maximumDate{0.0}; + Float minimumDate{0.0}; + DatePickerMinuteInterval minuteInterval{DatePickerMinuteInterval::MinuteInterval1}; + DatePickerMode mode{DatePickerMode::Date}; + Float timeZoneOffsetInMinutes{0.0}; +}; + +enum class AndroidDrawerLayoutKeyboardDismissMode { None, OnDrag }; + +static inline void fromRawValue(const RawValue &value, AndroidDrawerLayoutKeyboardDismissMode &result) { + auto string = (std::string)value; + if (string == "none") { result = AndroidDrawerLayoutKeyboardDismissMode::None; return; } + if (string == "on-drag") { result = AndroidDrawerLayoutKeyboardDismissMode::OnDrag; return; } + abort(); +} + +static inline std::string toString(const AndroidDrawerLayoutKeyboardDismissMode &value) { + switch (value) { + case AndroidDrawerLayoutKeyboardDismissMode::None: return "none"; + case AndroidDrawerLayoutKeyboardDismissMode::OnDrag: return "on-drag"; + } +} +enum class AndroidDrawerLayoutDrawerPosition { Left, Right }; + +static inline void fromRawValue(const RawValue &value, AndroidDrawerLayoutDrawerPosition &result) { + auto string = (std::string)value; + if (string == "left") { result = AndroidDrawerLayoutDrawerPosition::Left; return; } + if (string == "right") { result = AndroidDrawerLayoutDrawerPosition::Right; return; } + abort(); +} + +static inline std::string toString(const AndroidDrawerLayoutDrawerPosition &value) { + switch (value) { + case AndroidDrawerLayoutDrawerPosition::Left: return "left"; + case AndroidDrawerLayoutDrawerPosition::Right: return "right"; + } +} +enum class AndroidDrawerLayoutDrawerLockMode { Unlocked, LockedClosed, LockedOpen }; + +static inline void fromRawValue(const RawValue &value, AndroidDrawerLayoutDrawerLockMode &result) { + auto string = (std::string)value; + if (string == "unlocked") { result = AndroidDrawerLayoutDrawerLockMode::Unlocked; return; } + if (string == "locked-closed") { result = AndroidDrawerLayoutDrawerLockMode::LockedClosed; return; } + if (string == "locked-open") { result = AndroidDrawerLayoutDrawerLockMode::LockedOpen; return; } + abort(); +} + +static inline std::string toString(const AndroidDrawerLayoutDrawerLockMode &value) { + switch (value) { + case AndroidDrawerLayoutDrawerLockMode::Unlocked: return "unlocked"; + case AndroidDrawerLayoutDrawerLockMode::LockedClosed: return "locked-closed"; + case AndroidDrawerLayoutDrawerLockMode::LockedOpen: return "locked-open"; + } +} + +class AndroidDrawerLayoutProps final : public ViewProps { + public: + AndroidDrawerLayoutProps() = default; + AndroidDrawerLayoutProps(const AndroidDrawerLayoutProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + AndroidDrawerLayoutKeyboardDismissMode keyboardDismissMode{AndroidDrawerLayoutKeyboardDismissMode::None}; + SharedColor drawerBackgroundColor{}; + AndroidDrawerLayoutDrawerPosition drawerPosition{AndroidDrawerLayoutDrawerPosition::Left}; + Float drawerWidth{}; + AndroidDrawerLayoutDrawerLockMode drawerLockMode{AndroidDrawerLayoutDrawerLockMode::Unlocked}; + SharedColor statusBarBackgroundColor{}; +}; + +class RCTMaskedViewProps final : public ViewProps { + public: + RCTMaskedViewProps() = default; + RCTMaskedViewProps(const RCTMaskedViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + +}; + +class AndroidProgressBarProps final : public ViewProps { + public: + AndroidProgressBarProps() = default; + AndroidProgressBarProps(const AndroidProgressBarProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::string styleAttr{}; + std::string typeAttr{}; + bool indeterminate{false}; + double progress{0.0}; + bool animating{true}; + SharedColor color{}; + std::string testID{""}; +}; + +enum class RCTProgressViewProgressViewStyle { Default, Bar }; + +static inline void fromRawValue(const RawValue &value, RCTProgressViewProgressViewStyle &result) { + auto string = (std::string)value; + if (string == "default") { result = RCTProgressViewProgressViewStyle::Default; return; } + if (string == "bar") { result = RCTProgressViewProgressViewStyle::Bar; return; } + abort(); +} + +static inline std::string toString(const RCTProgressViewProgressViewStyle &value) { + switch (value) { + case RCTProgressViewProgressViewStyle::Default: return "default"; + case RCTProgressViewProgressViewStyle::Bar: return "bar"; + } +} + +class RCTProgressViewProps final : public ViewProps { + public: + RCTProgressViewProps() = default; + RCTProgressViewProps(const RCTProgressViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + RCTProgressViewProgressViewStyle progressViewStyle{RCTProgressViewProgressViewStyle::Default}; + Float progress{0.0}; + SharedColor progressTintColor{}; + SharedColor trackTintColor{}; + ImageSource progressImage{}; + ImageSource trackImage{}; +}; + +enum class AndroidSwipeRefreshLayoutSize { Default, Large }; + +static inline void fromRawValue(const RawValue &value, AndroidSwipeRefreshLayoutSize &result) { + auto string = (std::string)value; + if (string == "default") { result = AndroidSwipeRefreshLayoutSize::Default; return; } + if (string == "large") { result = AndroidSwipeRefreshLayoutSize::Large; return; } + abort(); +} + +static inline std::string toString(const AndroidSwipeRefreshLayoutSize &value) { + switch (value) { + case AndroidSwipeRefreshLayoutSize::Default: return "default"; + case AndroidSwipeRefreshLayoutSize::Large: return "large"; + } +} + +class AndroidSwipeRefreshLayoutProps final : public ViewProps { + public: + AndroidSwipeRefreshLayoutProps() = default; + AndroidSwipeRefreshLayoutProps(const AndroidSwipeRefreshLayoutProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool enabled{true}; + std::vector colors{}; + SharedColor progressBackgroundColor{}; + AndroidSwipeRefreshLayoutSize size{AndroidSwipeRefreshLayoutSize::Default}; + Float progressViewOffset{0.0}; + bool refreshing{false}; +}; + +class PullToRefreshViewProps final : public ViewProps { + public: + PullToRefreshViewProps() = default; + PullToRefreshViewProps(const PullToRefreshViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + SharedColor tintColor{}; + SharedColor titleColor{}; + std::string title{}; + Float progressViewOffset{0.0}; + bool refreshing{false}; +}; + +class SafeAreaViewProps final : public ViewProps { + public: + SafeAreaViewProps() = default; + SafeAreaViewProps(const SafeAreaViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool emulateUnlessSupported{false}; +}; + +class AndroidHorizontalScrollContentViewProps final : public ViewProps { + public: + AndroidHorizontalScrollContentViewProps() = default; + AndroidHorizontalScrollContentViewProps(const AndroidHorizontalScrollContentViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + +}; + +class RCTSegmentedControlProps final : public ViewProps { + public: + RCTSegmentedControlProps() = default; + RCTSegmentedControlProps(const RCTSegmentedControlProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::vector values{}; + int selectedIndex{0}; + bool enabled{true}; + SharedColor tintColor{}; + SharedColor textColor{}; + SharedColor backgroundColor{}; + bool momentary{false}; +}; + +class SliderProps final : public ViewProps { + public: + SliderProps() = default; + SliderProps(const SliderProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool disabled{false}; + bool enabled{true}; + ImageSource maximumTrackImage{}; + SharedColor maximumTrackTintColor{}; + double maximumValue{1.0}; + ImageSource minimumTrackImage{}; + SharedColor minimumTrackTintColor{}; + double minimumValue{0.0}; + double step{0.0}; + std::string testID{""}; + ImageSource thumbImage{}; + SharedColor thumbTintColor{}; + ImageSource trackImage{}; + double value{0.0}; +}; + +class AndroidSwitchProps final : public ViewProps { + public: + AndroidSwitchProps() = default; + AndroidSwitchProps(const AndroidSwitchProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool disabled{false}; + bool enabled{true}; + SharedColor thumbColor{}; + SharedColor trackColorForFalse{}; + SharedColor trackColorForTrue{}; + bool value{false}; + bool on{false}; + SharedColor thumbTintColor{}; + SharedColor trackTintColor{}; +}; + +class SwitchProps final : public ViewProps { + public: + SwitchProps() = default; + SwitchProps(const SwitchProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + bool disabled{false}; + bool value{false}; + SharedColor tintColor{}; + SharedColor onTintColor{}; + SharedColor thumbTintColor{}; + SharedColor thumbColor{}; + SharedColor trackColorForFalse{}; + SharedColor trackColorForTrue{}; +}; + +class InputAccessoryProps final : public ViewProps { + public: + InputAccessoryProps() = default; + InputAccessoryProps(const InputAccessoryProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + SharedColor backgroundColor{}; +}; + +class UnimplementedNativeViewProps final : public ViewProps { + public: + UnimplementedNativeViewProps() = default; + UnimplementedNativeViewProps(const UnimplementedNativeViewProps &sourceProps, const RawProps &rawProps); + +#pragma mark - Props + + std::string name{""}; +}; + +} // namespace react +} // namespace facebook diff --git a/vnext/codegen/react/components/rnwcore/ShadowNodes.cpp b/vnext/codegen/react/components/rnwcore/ShadowNodes.cpp new file mode 100644 index 00000000000..7efd3870d5f --- /dev/null +++ b/vnext/codegen/react/components/rnwcore/ShadowNodes.cpp @@ -0,0 +1,27 @@ + +/** + * 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 + +namespace facebook { +namespace react { + +extern const char ActivityIndicatorViewComponentName[] = "ActivityIndicatorView"; +extern const char DatePickerComponentName[] = "DatePicker"; +extern const char AndroidDrawerLayoutComponentName[] = "AndroidDrawerLayout"; +extern const char RCTMaskedViewComponentName[] = "RCTMaskedView"; +extern const char RCTProgressViewComponentName[] = "RCTProgressView"; +extern const char AndroidSwipeRefreshLayoutComponentName[] = "AndroidSwipeRefreshLayout"; +extern const char PullToRefreshViewComponentName[] = "PullToRefreshView"; +extern const char AndroidHorizontalScrollContentViewComponentName[] = "AndroidHorizontalScrollContentView"; +extern const char RCTSegmentedControlComponentName[] = "RCTSegmentedControl"; +extern const char SwitchComponentName[] = "Switch"; +extern const char UnimplementedNativeViewComponentName[] = "UnimplementedNativeView"; + +} // namespace react +} // namespace facebook diff --git a/vnext/codegen/react/components/rnwcore/ShadowNodes.h b/vnext/codegen/react/components/rnwcore/ShadowNodes.h new file mode 100644 index 00000000000..5c1673f8365 --- /dev/null +++ b/vnext/codegen/react/components/rnwcore/ShadowNodes.h @@ -0,0 +1,124 @@ + +/** + * 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 +#include +#include + +namespace facebook { +namespace react { + +extern const char ActivityIndicatorViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +using ActivityIndicatorViewShadowNode = ConcreteViewShadowNode< + ActivityIndicatorViewComponentName, + ActivityIndicatorViewProps>; + +extern const char DatePickerComponentName[]; + +/* + * `ShadowNode` for component. + */ +using DatePickerShadowNode = ConcreteViewShadowNode< + DatePickerComponentName, + DatePickerProps, +DatePickerEventEmitter>; + +extern const char AndroidDrawerLayoutComponentName[]; + +/* + * `ShadowNode` for component. + */ +using AndroidDrawerLayoutShadowNode = ConcreteViewShadowNode< + AndroidDrawerLayoutComponentName, + AndroidDrawerLayoutProps, +AndroidDrawerLayoutEventEmitter>; + +extern const char RCTMaskedViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +using RCTMaskedViewShadowNode = ConcreteViewShadowNode< + RCTMaskedViewComponentName, + RCTMaskedViewProps>; + +extern const char RCTProgressViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +using RCTProgressViewShadowNode = ConcreteViewShadowNode< + RCTProgressViewComponentName, + RCTProgressViewProps>; + +extern const char AndroidSwipeRefreshLayoutComponentName[]; + +/* + * `ShadowNode` for component. + */ +using AndroidSwipeRefreshLayoutShadowNode = ConcreteViewShadowNode< + AndroidSwipeRefreshLayoutComponentName, + AndroidSwipeRefreshLayoutProps, +AndroidSwipeRefreshLayoutEventEmitter>; + +extern const char PullToRefreshViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +using PullToRefreshViewShadowNode = ConcreteViewShadowNode< + PullToRefreshViewComponentName, + PullToRefreshViewProps, +PullToRefreshViewEventEmitter>; + +extern const char AndroidHorizontalScrollContentViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +using AndroidHorizontalScrollContentViewShadowNode = ConcreteViewShadowNode< + AndroidHorizontalScrollContentViewComponentName, + AndroidHorizontalScrollContentViewProps>; + +extern const char RCTSegmentedControlComponentName[]; + +/* + * `ShadowNode` for component. + */ +using RCTSegmentedControlShadowNode = ConcreteViewShadowNode< + RCTSegmentedControlComponentName, + RCTSegmentedControlProps, +RCTSegmentedControlEventEmitter>; + +extern const char SwitchComponentName[]; + +/* + * `ShadowNode` for component. + */ +using SwitchShadowNode = ConcreteViewShadowNode< + SwitchComponentName, + SwitchProps, +SwitchEventEmitter>; + +extern const char UnimplementedNativeViewComponentName[]; + +/* + * `ShadowNode` for component. + */ +using UnimplementedNativeViewShadowNode = ConcreteViewShadowNode< + UnimplementedNativeViewComponentName, + UnimplementedNativeViewProps>; + +} // namespace react +} // namespace facebook diff --git a/vnext/just-task.js b/vnext/just-task.js index 58971dabe2f..5e5f82745b7 100644 --- a/vnext/just-task.js +++ b/vnext/just-task.js @@ -30,7 +30,14 @@ task( 'codegen', series(cleanTask({paths: ['./codegen']}), () => { execSync( - 'npx --no-install @react-native-windows/codegen --files Libraries/**/Native*.js --namespace Microsoft::ReactNativeSpecs', + 'npx --no-install @react-native-windows/codegen --files Libraries/**/*Native*.js --namespace Microsoft::ReactNativeSpecs --libraryName rnwcore', + ); + execSync( + 'npx --no-install @react-native-windows/codegen --files Libraries/**/*NativeComponent.js --namespace Microsoft::ReactNativeSpecs --libraryName rnwcore', + ); + fs.writeFileSync( + 'codegen/.clang-format', + 'DisableFormat: true\nSortIncludes: false', ); }), );