diff --git a/Libraries/Components/Switch/SwitchSchema.js b/Libraries/Components/Switch/SwitchSchema.js new file mode 100644 index 000000000..de37583f6 --- /dev/null +++ b/Libraries/Components/Switch/SwitchSchema.js @@ -0,0 +1,94 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + * @flow + */ + +'use strict'; + +import type {SchemaType} from '../../../codegen/src/CodegenSchema.js'; + +const SwitchSchema: SchemaType = { + modules: { + Switch: { + components: { + Switch: { + 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: 'disabled', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'value', + optional: true, + typeAnnotation: { + type: 'BooleanTypeAnnotation', + default: false, + }, + }, + { + name: 'tintColor', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + { + name: 'onTintColor', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + { + name: 'thumbTintColor', + optional: true, + typeAnnotation: { + type: 'NativePrimitiveTypeAnnotation', + name: 'ColorPrimitive', + }, + }, + ], + }, + }, + }, + }, +}; + +module.exports = SwitchSchema; diff --git a/codegen/BUCK b/codegen/BUCK index 6e17966cd..02af00c7a 100644 --- a/codegen/BUCK +++ b/codegen/BUCK @@ -13,6 +13,16 @@ fb_native.sh_binary( "src/generators/__test_fixtures__/fixtures.js", "xplat//js:setup_env", ], +) + +fb_native.sh_binary( + name = "write_to_json", + main = "buck_tests/combine_js_to_schema.sh", + resources = [ + "buck_tests/combine-js-to-schema.js", + "buck_tests/combine_js_to_schema.sh", + "xplat//js:setup_env", + ], visibility = ["PUBLIC"], ) @@ -89,16 +99,16 @@ fb_xplat_cxx_binary( ], visibility = ["PUBLIC"], deps = [ - ":generated_fixture_library-SINGLE_COMPONENT_WITH_BOOLEAN_PROP", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_COLOR_PROP", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_ENUM_PROP", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_FLOAT_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_INTEGER_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_STRING_PROP", - ":generated_fixture_library-TWO_COMPONENTS_DIFFERENT_FILES", - ":generated_fixture_library-TWO_COMPONENTS_SAME_FILE", + ":generated_components-SINGLE_COMPONENT_WITH_BOOLEAN_PROP", + ":generated_components-SINGLE_COMPONENT_WITH_COLOR_PROP", + ":generated_components-SINGLE_COMPONENT_WITH_ENUM_PROP", + ":generated_components-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_EVENT_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_FLOAT_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_INTEGER_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_STRING_PROP", + ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", + ":generated_components-TWO_COMPONENTS_SAME_FILE", ], ) @@ -121,15 +131,15 @@ rn_xplat_cxx_library( "PUBLIC", ], deps = [ - ":generated_fixture_library-SINGLE_COMPONENT_WITH_BOOLEAN_PROP", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_COLOR_PROP", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_ENUM_PROP", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_EVENT_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_FLOAT_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_INTEGER_PROPS", - ":generated_fixture_library-SINGLE_COMPONENT_WITH_STRING_PROP", - ":generated_fixture_library-TWO_COMPONENTS_DIFFERENT_FILES", - ":generated_fixture_library-TWO_COMPONENTS_SAME_FILE", + ":generated_components-SINGLE_COMPONENT_WITH_BOOLEAN_PROP", + ":generated_components-SINGLE_COMPONENT_WITH_COLOR_PROP", + ":generated_components-SINGLE_COMPONENT_WITH_ENUM_PROP", + ":generated_components-SINGLE_COMPONENT_WITH_EVENT_NESTED_OBJECT_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_EVENT_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_FLOAT_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_INTEGER_PROPS", + ":generated_components-SINGLE_COMPONENT_WITH_STRING_PROP", + ":generated_components-TWO_COMPONENTS_DIFFERENT_FILES", + ":generated_components-TWO_COMPONENTS_SAME_FILE", ], ) diff --git a/codegen/DEFS.bzl b/codegen/DEFS.bzl index 646c50726..bb6470e7c 100644 --- a/codegen/DEFS.bzl +++ b/codegen/DEFS.bzl @@ -1,7 +1,11 @@ -load("@fbsource//tools/build_defs:default_platform_defs.bzl", "ANDROID", "APPLE") load("@fbsource//tools/build_defs:fb_native_wrapper.bzl", "fb_native") +load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "get_debug_preprocessor_flags") load( "//tools/build_defs/oss:rn_defs.bzl", + "ANDROID", + "APPLE", + "get_apple_compiler_flags", + "get_apple_inspector_flags", "react_native_xplat_target", "rn_xplat_cxx_library", ) @@ -9,26 +13,32 @@ load( def rn_codegen_test( fixture_name = ""): copy_schema_name = "copy_schema-{}".format(fixture_name) - generate_fixtures_rule_name = "generate_fixtures-{}".format(fixture_name) - generate_component_descriptor_h_name = "generate_component_descriptor_h-{}".format(fixture_name) - generate_event_emitter_cpp_name = "generate_event_emitter_cpp-{}".format(fixture_name) - generate_event_emitter_h_name = "generate_event_emitter_h-{}".format(fixture_name) - generate_props_cpp_name = "generate_props_cpp-{}".format(fixture_name) - generate_props_h_name = "generated_props_h-{}".format(fixture_name) - generate_shadow_node_h_name = "generated_shadow_node_h-{}".format(fixture_name) fb_native.genrule( name = copy_schema_name, srcs = [], - cmd = "$(exe :copy_fixture_schema) {} $OUT".format(fixture_name), + cmd = "$(exe xplat//js/react-native-github/codegen:copy_fixture_schema) {} $OUT".format(fixture_name), out = "schema-{}.json".format(fixture_name), ) + rn_codegen(fixture_name, ":{}".format(copy_schema_name)) + +def rn_codegen( + name = "", + schema_target = ""): + generate_fixtures_rule_name = "generate_fixtures-{}".format(name) + generate_component_descriptor_h_name = "generate_component_descriptor_h-{}".format(name) + generate_event_emitter_cpp_name = "generate_event_emitter_cpp-{}".format(name) + generate_event_emitter_h_name = "generate_event_emitter_h-{}".format(name) + generate_props_cpp_name = "generate_props_cpp-{}".format(name) + generate_props_h_name = "generated_props_h-{}".format(name) + generate_shadow_node_h_name = "generated_shadow_node_h-{}".format(name) + fb_native.genrule( name = generate_fixtures_rule_name, srcs = [], - cmd = "$(exe :rn_codegen) $(location :{}) {} $OUT".format(copy_schema_name, fixture_name), - out = "codegenfiles-{}".format(fixture_name), + cmd = "$(exe xplat//js/react-native-github/codegen:rn_codegen) $(location {}) {} $OUT".format(schema_target, name), + out = "codegenfiles-{}".format(name), ) fb_native.genrule( @@ -69,7 +79,7 @@ def rn_codegen_test( # libs rn_xplat_cxx_library( - name = "generated_fixture_library-{}".format(fixture_name), + name = "generated_components-{}".format(name), srcs = [ ":{}".format(generate_event_emitter_cpp_name), ":{}".format(generate_props_cpp_name), @@ -86,19 +96,31 @@ def rn_codegen_test( "Props.h": ":{}".format(generate_props_h_name), "ShadowNodes.h": ":{}".format(generate_shadow_node_h_name), }, - header_namespace = "react/components/{}".format(fixture_name), + header_namespace = "react/components/{}".format(name), compiler_flags = [ "-fexceptions", "-frtti", "-std=c++14", "-Wall", ], + fbobjc_compiler_flags = get_apple_compiler_flags(), + fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(), platforms = (ANDROID, APPLE), preprocessor_flags = [ "-DLOG_TAG=\"ReactNative\"", "-DWITH_FBSYSTRACE=1", ], + visibility = ["PUBLIC"], deps = [ + "xplat//fbsystrace:fbsystrace", + "xplat//folly:headers_only", + "xplat//folly:memory", + "xplat//folly:molly", + "xplat//third-party/glog:glog", + "xplat//yoga:yoga", + react_native_xplat_target("fabric/debug:debug"), + react_native_xplat_target("fabric/core:core"), + react_native_xplat_target("fabric/graphics:graphics"), react_native_xplat_target("fabric/components/view:view"), ], ) diff --git a/codegen/buck_tests/combine-js-to-schema.js b/codegen/buck_tests/combine-js-to-schema.js new file mode 100644 index 000000000..cb58bc4ed --- /dev/null +++ b/codegen/buck_tests/combine-js-to-schema.js @@ -0,0 +1,36 @@ +/** + * 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. + * + * @flow + * @format + */ + +'use strict'; + +const fs = require('fs'); + +const args = process.argv.slice(2); +if (args.length !== 2) { + throw new Error( + 'Expected to receive the input path and output path as arguments', + ); +} + +const src = args[0]; +const outputPath = args[1]; + +let file; + +try { + // Eventually this will be replaced with a script that reads and parses + // the file via ast + // $FlowFixMe Can't require dynamic variables + file = require(src); +} catch (err) { + throw new Error(`Can't require file at ${src}`); +} + +fs.writeFileSync(outputPath, JSON.stringify(file, null, 2)); diff --git a/codegen/buck_tests/combine_js_to_schema.sh b/codegen/buck_tests/combine_js_to_schema.sh new file mode 100755 index 000000000..fd8920e71 --- /dev/null +++ b/codegen/buck_tests/combine_js_to_schema.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e +set -u + +THIS_DIR=$(cd -P "$(dirname "$(readlink "${BASH_SOURCE[0]}" || echo "${BASH_SOURCE[0]}")")" && pwd) + +# shellcheck source=xplat/js/env-utils/setup_env_vars.sh +source "$THIS_DIR/../../../env-utils/setup_env_vars.sh" + +exec "$FLOW_NODE_BINARY" "$THIS_DIR/combine-js-to-schema.js" "$@"