Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ type NativeProps = $ReadOnly<{|
/**
* Specifies the side of the screen from which the drawer will slide in.
*/
drawerPosition: ?Int32,
drawerPosition?: WithDefault<'left' | 'right', 'left'>,

/**
* Specifies the width of the drawer, more precisely the width of the view that be pulled in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,11 @@

const Platform = require('../../Utilities/Platform');
const React = require('react');
const ReactNative = require('../../Renderer/shims/ReactNative');
const StatusBar = require('../StatusBar/StatusBar');
const StyleSheet = require('../../StyleSheet/StyleSheet');
const UIManager = require('../../ReactNative/UIManager');
const View = require('../View/View');
const nullthrows = require('nullthrows');

const DrawerConsts = UIManager.getViewManagerConfig('AndroidDrawerLayout')
.Constants;
const dismissKeyboard = require('../../Utilities/dismissKeyboard');
import AndroidDrawerLayoutNativeComponent, {
Commands,
Expand Down Expand Up @@ -67,7 +63,7 @@ type Props = $ReadOnly<{|
/**
* Specifies the side of the screen from which the drawer will slide in.
*/
drawerPosition: ?number,
drawerPosition: ?('left' | 'right'),

/**
* Specifies the width of the drawer, more precisely the width of the view that be pulled in
Expand Down Expand Up @@ -148,7 +144,7 @@ type State = {|
* return (
* <DrawerLayoutAndroid
* drawerWidth={300}
* drawerPosition={DrawerLayoutAndroid.positions.Left}
* drawerPosition="left"
* renderNavigationView={() => navigationView}>
* <View style={{flex: 1, alignItems: 'center'}}>
* <Text style={{margin: 10, fontSize: 15, textAlign: 'right'}}>Hello</Text>
Expand All @@ -160,7 +156,13 @@ type State = {|
* ```
*/
class DrawerLayoutAndroid extends React.Component<Props, State> {
static positions = DrawerConsts.DrawerPosition;
static get positions(): mixed {
console.warn(
'Setting DrawerLayoutAndroid drawerPosition using `DrawerLayoutAndroid.positions` is deprecated. Instead pass the string value "left" or "right"',
);

return {Left: 'left', Right: 'right'};
}
static defaultProps = {
drawerBackgroundColor: 'white',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('<DrawerLayoutAndroid />', () => {
const instance = render.create(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand All @@ -36,7 +36,7 @@ describe('<DrawerLayoutAndroid />', () => {
const output = render.shallow(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand All @@ -49,7 +49,7 @@ describe('<DrawerLayoutAndroid />', () => {
const output = render.shallow(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand All @@ -62,7 +62,7 @@ describe('<DrawerLayoutAndroid />', () => {
const instance = render.create(
<DrawerLayoutAndroid
drawerWidth={300}
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
renderNavigationView={() => <View />}
/>,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when mocked 1`] = `
<AndroidDrawerLayout
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
onDrawerClose={[Function]}
onDrawerOpen={[Function]}
Expand Down Expand Up @@ -55,7 +55,7 @@ exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when moc
exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when not mocked 1`] = `
<AndroidDrawerLayout
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
onDrawerClose={[Function]}
onDrawerOpen={[Function]}
Expand Down Expand Up @@ -107,7 +107,7 @@ exports[`<DrawerLayoutAndroid /> should render as <DrawerLayoutAndroid> when not
exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid> when mocked 1`] = `
<DrawerLayoutAndroid
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
renderNavigationView={[Function]}
/>
Expand All @@ -116,7 +116,7 @@ exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid>
exports[`<DrawerLayoutAndroid /> should shallow render as <DrawerLayoutAndroid> when not mocked 1`] = `
<DrawerLayoutAndroid
drawerBackgroundColor="white"
drawerPosition={10}
drawerPosition="left"
drawerWidth={300}
renderNavigationView={[Function]}
/>
Expand Down
2 changes: 1 addition & 1 deletion RNTester/js/RNTesterApp.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
}
return (
<DrawerLayoutAndroid
drawerPosition={DrawerLayoutAndroid.positions.Left}
drawerPosition="left"
drawerWidth={Dimensions.get('window').width - DRAWER_WIDTH_LEFT}
keyboardDismissMode="on-drag"
onDrawerOpen={() => {
Expand Down
1 change: 1 addition & 0 deletions packages/react-native-codegen/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fb_native.genrule(

rn_codegen(
name = "codegen_tests",
native_module_spec_name = "FBReactNativeTestSpec",
schema_target = ":codegen_tests_schema",
)

Expand Down
17 changes: 9 additions & 8 deletions packages/react-native-codegen/DEFS.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ load(
)

def rn_codegen(
native_module_spec_name,
name = "",
schema_target = ""):
generate_fixtures_rule_name = "generate_fixtures-{}".format(name)
Expand All @@ -40,7 +41,7 @@ def rn_codegen(
fb_native.genrule(
name = generate_fixtures_rule_name,
srcs = native.glob(["src/generators/**/*.js"]),
cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT".format(schema_target, name),
cmd = "$(exe fbsource//xplat/js/react-native-github/packages/react-native-codegen:rn_codegen) $(location {}) {} $OUT {}".format(schema_target, name, native_module_spec_name),
out = "codegenfiles-{}".format(name),
)

Expand Down Expand Up @@ -125,14 +126,14 @@ def rn_codegen(

fb_native.genrule(
name = generate_module_hobjcpp_name,
cmd = "cp $(location :{})/RCTNativeModules.h $OUT".format(generate_fixtures_rule_name),
out = "RCTNativeModules.h",
cmd = "cp $(location :{})/{}.h $OUT".format(generate_fixtures_rule_name, native_module_spec_name),
out = "{}.h".format(native_module_spec_name),
)

fb_native.genrule(
name = generate_module_mm_name,
cmd = "cp $(location :{})/RCTNativeModules.mm $OUT".format(generate_fixtures_rule_name),
out = "RCTNativeModules.mm",
cmd = "cp $(location :{})/{}-generated.mm $OUT".format(generate_fixtures_rule_name, native_module_spec_name),
out = "{}-generated.mm".format(native_module_spec_name),
)

# libs
Expand Down Expand Up @@ -236,10 +237,10 @@ def rn_codegen(
":{}".format(generate_module_hobjcpp_name),
],
ios_exported_headers = {
"RCTNativeModules.h": ":{}".format(generate_module_hobjcpp_name),
"RCTNativeModules.mm": ":{}".format(generate_module_mm_name),
"{}.h".format(native_module_spec_name): ":{}".format(generate_module_hobjcpp_name),
"{}-generated.mm".format(native_module_spec_name): ":{}".format(generate_module_mm_name),
},
header_namespace = "react/modules/{}".format(name),
header_namespace = native_module_spec_name,
compiler_flags = [
"-fexceptions",
"-frtti",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native-codegen/buck_tests/emptyFile.mm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#import <react/components/codegen_tests/ComponentDescriptors.h>
#import <react/components/codegen_tests/ComponentViewHelpers.h>
#import <react/modules/codegen_tests/RCTNativeModules.h>
#import <react/modules/codegen_tests/RCTNativeModules.mm>
#import <FBReactNativeTestSpec/FBReactNativeTestSpec.h>
#import <FBReactNativeTestSpec/FBReactNativeTestSpec-generated.mm>

// TODO: Import every prop and event to asset they're generated

Expand Down
7 changes: 4 additions & 3 deletions packages/react-native-codegen/buck_tests/generate-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const fs = require('fs');
const mkdirp = require('mkdirp');

const args = process.argv.slice(2);
if (args.length !== 3) {
if (args.length !== 4) {
throw new Error(
`Expected to receive path to schema, library name, and output directory. Received ${args.join(
`Expected to receive path to schema, library name, output directory and module spec name. Received ${args.join(
', ',
)}`,
);
Expand All @@ -26,6 +26,7 @@ if (args.length !== 3) {
const schemaPath = args[0];
const libraryName = args[1];
const outputDirectory = args[2];
const moduleSpecName = args[3];

const schemaText = fs.readFileSync(schemaPath, 'utf-8');

Expand All @@ -43,7 +44,7 @@ try {
}

RNCodegen.generate(
{libraryName, schema, outputDirectory},
{libraryName, schema, outputDirectory, moduleSpecName},
{
generators: [
'descriptors',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type AnotherArray = Array<ArrayType>;

export interface Spec extends TurboModule {
+getArray: (a: Array<any>) => Array<string>;
+getReadOnlyArray: (a: Array<any>) => $ReadOnlyArray<string>;
+getArrayWithAlias: (a: AnotherArray, b: Array<ArrayType>) => AnotherArray;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* 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';

import type {TurboModule} from 'react-native/Libraries/TurboModule/RCTExport';
import * as TurboModuleRegistry from 'react-native/Libraries/TurboModule/TurboModuleRegistry';

export interface Spec extends TurboModule {
+getBool: () => ?boolean;
+getNumber: () => ?number;
+getString: () => ?string;
+getArray: () => ?Array<any>;
+getObject: () => ?Object;
+getValueWithPromise: () => ?Promise<string>;
}

export default TurboModuleRegistry.getEnforcing<Spec>('SampleTurboModule');
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type AnotherGenericObject = GenericObject;

export interface Spec extends TurboModule {
+getGenericObject: (arg: Object) => Object;
+getGenericObjectReadOnly: (arg: Object) => $ReadOnly<{|a: string|}>;
+getGenericObjectWithAlias: (arg: GenericObject) => AnotherGenericObject;
+difficultObject: (A: {|
D: boolean,
Expand Down
22 changes: 11 additions & 11 deletions packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,10 @@ export type PrimitiveTypeAnnotation = $ReadOnly<{|

export type FunctionTypeAnnotationParamTypeAnnotation =
| $ReadOnly<{|
type: 'AnyTypeAnnotation' | PrimitiveTypeAnnotationType,
type:
| 'AnyTypeAnnotation'
| 'FunctionTypeAnnotation'
| PrimitiveTypeAnnotationType,
|}>
| $ReadOnly<{|
type: 'ArrayTypeAnnotation',
Expand All @@ -158,11 +161,6 @@ export type FunctionTypeAnnotationParamTypeAnnotation =
| $ReadOnly<{|
type: 'ObjectTypeAnnotation',
properties: ?$ReadOnlyArray<ObjectParamTypeAnnotation>,
|}>
| $ReadOnly<{|
type: 'FunctionTypeAnnotation',
params: $ReadOnlyArray<FunctionTypeAnnotationParam>,
returnTypeAnnotation: FunctionTypeAnnotationReturn,
|}>;

export type FunctionTypeAnnotationReturnArrayElementType = FunctionTypeAnnotationParamTypeAnnotation;
Expand All @@ -175,17 +173,19 @@ export type ObjectParamTypeAnnotation = $ReadOnly<{|

export type FunctionTypeAnnotationReturn =
| $ReadOnly<{|
type: PrimitiveTypeAnnotationType | 'VoidTypeAnnotation',
nullable: boolean,
type:
| PrimitiveTypeAnnotationType
| 'VoidTypeAnnotation'
| 'GenericPromiseTypeAnnotation',
|}>
| $ReadOnly<{|
nullable: boolean,
type: 'ArrayTypeAnnotation',
elementType: ?FunctionTypeAnnotationReturnArrayElementType,
|}>
| $ReadOnly<{|
type: 'GenericPromiseTypeAnnotation',
resolvedType: FunctionTypeAnnotationReturn,
|}>
| $ReadOnly<{|
nullable: boolean,
type: 'ObjectTypeAnnotation',
properties: ?$ReadOnlyArray<ObjectParamTypeAnnotation>,
|}>;
Expand Down
9 changes: 4 additions & 5 deletions packages/react-native-codegen/src/generators/RNCodegen.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Options = $ReadOnly<{|
libraryName: string,
schema: SchemaType,
outputDirectory: string,
moduleSpecName: string,
|}>;

type Generators =
Expand All @@ -50,8 +51,7 @@ type Generators =
| 'props'
| 'tests'
| 'shadow-nodes'
| 'modules'
| 'view-configs';
| 'modules';

type Config = $ReadOnly<{|
generators: Array<Generators>,
Expand Down Expand Up @@ -79,7 +79,6 @@ const GENERATORS = {
generateShadowNodeCpp.generate,
generateShadowNodeH.generate,
],
'view-configs': [generateViewConfigJs.generate],
};

function writeMapToFiles(map: Map<string, string>, outputDir: string) {
Expand Down Expand Up @@ -118,15 +117,15 @@ function checkFilesForChanges(

module.exports = {
generate(
{libraryName, schema, outputDirectory}: Options,
{libraryName, schema, outputDirectory, moduleSpecName}: Options,
{generators, test}: Config,
): boolean {
schemaValidator.validate(schema);

const generatedFiles = [];
for (const name of generators) {
for (const generator of GENERATORS[name]) {
generatedFiles.push(...generator(libraryName, schema));
generatedFiles.push(...generator(libraryName, schema, moduleSpecName));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@ using ::_CLASSNAME_::ComponentDescriptor = ConcreteComponentDescriptor<::_CLASSN
`.trim();

module.exports = {
generate(libraryName: string, schema: SchemaType): FilesOutput {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
): FilesOutput {
const fileName = 'ComponentDescriptors.h';

const componentDescriptors = Object.keys(schema.modules)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,11 @@ function generateCommandHandler(
}

module.exports = {
generate(libraryName: string, schema: SchemaType): FilesOutput {
generate(
libraryName: string,
schema: SchemaType,
moduleSpecName: string,
): FilesOutput {
const fileName = 'RCTComponentViewHelpers.h';

const componentContent = Object.keys(schema.modules)
Expand Down
Loading