-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/line-break-strategy-ios
- Loading branch information
Showing
173 changed files
with
21,687 additions
and
18,455 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,9 @@ indent_size = 2 | |
[*.gradle] | ||
indent_size = 4 | ||
|
||
[*.kts] | ||
indent_size = 4 | ||
|
||
[BUCK] | ||
indent_size = 4 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
Libraries/Animated/__tests__/createAnimatedComponentInjection-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* 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. | ||
* | ||
* @emails oncall+react_native | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const createAnimatedComponent = require('../createAnimatedComponent'); | ||
const createAnimatedComponentInjection = require('../createAnimatedComponentInjection'); | ||
const React = require('react'); | ||
|
||
function injected<TProps: {...}, TInstance>( | ||
Component: React.AbstractComponent<TProps, TInstance>, | ||
): React.AbstractComponent<TProps, TInstance> { | ||
return createAnimatedComponent(Component); | ||
} | ||
|
||
beforeEach(() => { | ||
jest.resetModules(); | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
test('does nothing without injection', () => { | ||
expect(typeof createAnimatedComponent).toBe('function'); | ||
expect(createAnimatedComponent).not.toBe(injected); | ||
}); | ||
|
||
test('injection overrides `createAnimatedComponent`', () => { | ||
createAnimatedComponentInjection.inject(injected); | ||
|
||
expect(createAnimatedComponent).toBe(injected); | ||
}); | ||
|
||
test('injection errors if called too late', () => { | ||
jest.spyOn(console, 'error').mockReturnValue(undefined); | ||
|
||
// Causes `createAnimatedComponent` to be initialized. | ||
createAnimatedComponent; | ||
|
||
createAnimatedComponentInjection.inject(injected); | ||
|
||
expect(createAnimatedComponent).not.toBe(injected); | ||
expect(console.error).toBeCalledWith( | ||
'createAnimatedComponentInjection: Must be called before `createAnimatedComponent`.', | ||
); | ||
}); | ||
|
||
test('injection errors if called more than once', () => { | ||
jest.spyOn(console, 'error').mockReturnValue(undefined); | ||
|
||
createAnimatedComponentInjection.inject(injected); | ||
|
||
expect(createAnimatedComponent).toBe(injected); | ||
expect(console.error).not.toBeCalled(); | ||
|
||
createAnimatedComponentInjection.inject(injected); | ||
|
||
expect(console.error).toBeCalledWith( | ||
'createAnimatedComponentInjection: Cannot be called more than once.', | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* 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 strict-local | ||
* @format | ||
*/ | ||
|
||
import * as React from 'react'; | ||
|
||
type createAnimatedComponent = <TProps: {...}, TInstance>( | ||
Component: React.AbstractComponent<TProps, TInstance>, | ||
) => React.AbstractComponent<TProps, TInstance>; | ||
|
||
// This can be undefined, null, or the experimental implementation. If this is | ||
// null, that means `createAnimatedComponent` has already been initialized and | ||
// it is too late to call `inject`. | ||
let injected: ?createAnimatedComponent; | ||
|
||
/** | ||
* Call during bundle initialization to opt-in to new `createAnimatedComponent`. | ||
*/ | ||
export function inject(newInjected: createAnimatedComponent): void { | ||
if (injected !== undefined) { | ||
if (__DEV__) { | ||
console.error( | ||
'createAnimatedComponentInjection: ' + | ||
(injected == null | ||
? 'Must be called before `createAnimatedComponent`.' | ||
: 'Cannot be called more than once.'), | ||
); | ||
} | ||
return; | ||
} | ||
injected = newInjected; | ||
} | ||
|
||
/** | ||
* Only called by `createAnimatedComponent.js`. | ||
*/ | ||
export function recordAndRetrieve(): createAnimatedComponent | null { | ||
if (injected === undefined) { | ||
injected = null; | ||
} | ||
return injected; | ||
} |
30 changes: 30 additions & 0 deletions
30
Libraries/Animated/createAnimatedComponent_EXPERIMENTAL.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
* | ||
* @flow strict-local | ||
* @format | ||
*/ | ||
|
||
import useAnimatedProps from './useAnimatedProps'; | ||
import useMergeRefs from '../Utilities/useMergeRefs'; | ||
import * as React from 'react'; | ||
|
||
/** | ||
* Experimental implementation of `createAnimatedComponent` that is intended to | ||
* be compatible with concurrent rendering. | ||
*/ | ||
export default function createAnimatedComponent<TProps: {...}, TInstance>( | ||
Component: React.AbstractComponent<TProps, TInstance>, | ||
): React.AbstractComponent<TProps, TInstance> { | ||
return React.forwardRef((props, forwardedRef) => { | ||
const [reducedProps, callbackRef] = useAnimatedProps<TProps, TInstance>( | ||
props, | ||
); | ||
const ref = useMergeRefs<TInstance | null>(callbackRef, forwardedRef); | ||
|
||
return <Component {...reducedProps} ref={ref} />; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.