-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1329ae1
commit 4c50ef9
Showing
9 changed files
with
149 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
const { promises: fs } = require('fs'); | ||
const path = require('path'); | ||
|
||
const root = path.resolve(__dirname, '..'); | ||
const output = path.join(root, 'lib', 'typescript'); | ||
|
||
/** | ||
* List of React Native props not used by React Native Paper. | ||
* Feel free to delete props from this list when | ||
* React Native Paper has defined/uses one with the same name. | ||
* This script was originally created to detect if TypeScript | ||
* has exported a large union of props from ViewProps. | ||
* More info: https://github.com/callstack/react-native-paper/pull/3603 | ||
*/ | ||
const unusedViewProps = [ | ||
'nativeID', | ||
'accessibilityActions', | ||
'accessibilityRole', | ||
'accessibilityValue', | ||
'onAccessibilityAction', | ||
'accessibilityLabelledBy', | ||
'accessibilityLiveRegion', | ||
'accessibilityLanguage', | ||
'accessibilityViewIsModal', | ||
'onAccessibilityEscape', | ||
'onAccessibilityTap', | ||
'onMagicTap', | ||
'accessibilityIgnoresInvertColors', | ||
'hitSlop', | ||
'removeClippedSubviews', | ||
'collapsable', | ||
'needsOffscreenAlphaCompositing', | ||
'renderToHardwareTextureAndroid', | ||
'shouldRasterizeIOS', | ||
'isTVSelectable', | ||
'hasTVPreferredFocus', | ||
'tvParallaxProperties', | ||
'tvParallaxShiftDistanceX', | ||
'tvParallaxShiftDistanceY', | ||
'tvParallaxTiltAngle', | ||
'tvParallaxMagnification', | ||
'onStartShouldSetResponder', | ||
'onMoveShouldSetResponder', | ||
'onResponderEnd', | ||
'onResponderGrant', | ||
'onResponderReject', | ||
'onResponderMove', | ||
'onResponderRelease', | ||
'onResponderStart', | ||
'onResponderTerminationRequest', | ||
'onResponderTerminate', | ||
'onStartShouldSetResponderCapture', | ||
'onMoveShouldSetResponderCapture', | ||
'onTouchStart', | ||
'onTouchMove', | ||
'onTouchEnd', | ||
'onTouchCancel', | ||
'onTouchEndCapture', | ||
'onPointerEnter', | ||
'onPointerEnterCapture', | ||
'onPointerLeave', | ||
'onPointerLeaveCapture', | ||
'onPointerMove', | ||
'onPointerMoveCapture', | ||
'onPointerCancel', | ||
'onPointerCancelCapture', | ||
'onPointerDown', | ||
'onPointerDownCapture', | ||
'onPointerUp', | ||
'onPointerUpCapture', | ||
'onHoverIn', | ||
'onHoverOut', | ||
'cancelable', | ||
'delayHoverIn', | ||
'delayHoverOut', | ||
'pressRetentionOffset', | ||
'android_disableSound', | ||
'android_ripple', | ||
'testOnly_pressed', | ||
'unstable_pressDelay', | ||
]; | ||
|
||
async function* getFiles(directory) { | ||
const entries = await fs.readdir(directory, { withFileTypes: true }); | ||
for (const entry of entries) { | ||
const res = path.resolve(directory, entry.name); | ||
if (entry.isDirectory()) { | ||
yield* getFiles(res); | ||
} else { | ||
yield res; | ||
} | ||
} | ||
} | ||
|
||
async function main() { | ||
for await (const file of getFiles(output)) { | ||
const content = await fs.readFile(file); | ||
for (const prop of unusedViewProps) { | ||
if (content.includes(prop)) { | ||
throw new Error( | ||
`Found text '${prop}' in '${file}'. Please use the wrapped 'forwardRef' in 'src/utils/forwardRef.ts', export some return types, or modify 'scripts/typescript-output-lint.js'` | ||
); | ||
} | ||
} | ||
} | ||
|
||
console.log('✅ No React Native props mentioned in TypeScript files'); | ||
} | ||
|
||
main().catch((reason) => { | ||
console.error(reason); | ||
process.exit(1); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { | ||
forwardRef as reactForwardRef, | ||
ForwardRefRenderFunction, | ||
PropsWithoutRef, | ||
RefAttributes, | ||
ForwardRefExoticComponent, | ||
} from 'react'; | ||
|
||
export type ForwarRefComponent<T, P = {}> = ForwardRefExoticComponent< | ||
PropsWithoutRef<P> & RefAttributes<T> | ||
>; | ||
|
||
/** | ||
* TypeScript generated a large union of props from `ViewProps` in | ||
* `d.ts` files when using `React.forwardRef`. To prevent this | ||
* `ForwarRefComponent` was created and exported. Use this | ||
* `forwardRef` instead of `React.forwardRef` so you don't have to | ||
* import `ForwarRefComponent`. | ||
* More info: https://github.com/callstack/react-native-paper/pull/3603 | ||
*/ | ||
export const forwardRef: <T, P = {}>( | ||
render: ForwardRefRenderFunction<T, P> | ||
) => ForwarRefComponent<T, P> = reactForwardRef; |