forked from necolas/react-native-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close necolas#1746 Fix necolas#1665
- Loading branch information
Showing
16 changed files
with
275 additions
and
167 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
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
26 changes: 26 additions & 0 deletions
26
src/exports/TouchableWithoutFeedback/__tests__/index-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,26 @@ | ||
import React from 'react'; | ||
import { render } from '@testing-library/react'; | ||
import TouchableWithoutFeedback from '../'; | ||
import View from '../../View'; | ||
|
||
describe('components/TouchableWithoutFeedback', () => { | ||
test('forwards ref', () => { | ||
const ref = jest.fn(); | ||
render( | ||
<TouchableWithoutFeedback ref={ref}> | ||
<View /> | ||
</TouchableWithoutFeedback> | ||
); | ||
expect(ref).toHaveBeenCalled(); | ||
}); | ||
|
||
test('forwards ref of child', () => { | ||
const ref = jest.fn(); | ||
render( | ||
<TouchableWithoutFeedback> | ||
<View ref={ref} /> | ||
</TouchableWithoutFeedback> | ||
); | ||
expect(ref).toHaveBeenCalled(); | ||
}); | ||
}); |
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,31 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
import * as React from 'react'; | ||
import mergeRefs from '..'; | ||
import { render } from '@testing-library/react'; | ||
|
||
describe('modules/mergeRefs', () => { | ||
test('merges refs of different types', () => { | ||
const ref = React.createRef(null); | ||
let functionRefValue = null; | ||
let hookRef; | ||
function Component() { | ||
const functionRef = x => { | ||
functionRefValue = x; | ||
}; | ||
hookRef = React.useRef(null); | ||
return <div ref={mergeRefs(ref, hookRef, functionRef)} />; | ||
} | ||
|
||
render(<Component />); | ||
|
||
expect(ref.current).not.toBe(null); | ||
expect(hookRef.current).not.toBe(null); | ||
expect(functionRefValue).not.toBe(null); | ||
}); | ||
}); |
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,33 @@ | ||
/** | ||
* 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 | ||
*/ | ||
|
||
import * as React from 'react'; | ||
|
||
export default function mergeRefs(...args: $ReadOnlyArray<React.ElementRef<any>>) { | ||
return function forwardRef(node: HTMLElement | null) { | ||
args.forEach((ref: React.ElementRef<any>) => { | ||
if (ref == null) { | ||
return; | ||
} | ||
if (typeof ref === 'function') { | ||
ref(node); | ||
return; | ||
} | ||
if (typeof ref === 'object') { | ||
ref.current = node; | ||
return; | ||
} | ||
console.error( | ||
`mergeRefs cannot handle Refs of type boolean, number or string, received ref ${String( | ||
ref | ||
)}` | ||
); | ||
}); | ||
}; | ||
} |
Oops, something went wrong.