mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
0a68763743
Summary: In order to cleanup the callsites that are not using Animated's native driver, we are going to make useNativeDriver a required option so people have to think about whether they want the native driver or not. I made this change by changing [Animated.js](https://fburl.com/ritcebri) to have this animation config type: ``` export type AnimationConfig = { isInteraction?: boolean, useNativeDriver: true, onComplete?: ?EndCallback, iterations?: number, }; ``` This causes Flow to error anywhere where useNativeDriver isn't set or where it is set to false. I then used these Flow errors to codemod the callsites. I got the location of the Flow errors by running: ``` flow status --strip-root --json --message-width=0 | jq '.errors | [.[].extra | .[].message | .[].loc | objects | {source: .source, start: .start, end: .end}]' ``` And then ran this codemod: ``` const json = JSON.parse('JSON RESULT FROM FLOW'); const fileLookup = new Map(); json.forEach(item => { if (!fileLookup.has(item.source)) { fileLookup.set(item.source, []); } fileLookup.get(item.source).push(item); }); export default function transformer(file, api) { const j = api.jscodeshift; const filePath = file.path; if (!fileLookup.has(filePath)) { return; } const locationInfo = fileLookup.get(filePath); return j(file.source) .find(j.ObjectExpression) .forEach(path => { if ( path.node.properties.some( property => property != null && property.key != null && property.key.name === 'useNativeDriver', ) ) { return; } const hasErrorOnLine = locationInfo.some( singleLocationInfo => singleLocationInfo.start.line === path.node.loc.start.line && Math.abs( singleLocationInfo.start.column - path.node.loc.start.column, ) <= 2, ); if (!hasErrorOnLine) { return; } path.node.properties.push( j.property( 'init', j.identifier('useNativeDriver'), j.booleanLiteral(false), ), ); }) .toSource(); } export const parser = 'flow'; ``` ``` yarn jscodeshift --parser=flow --transform addUseNativeDriver.js RKJSModules react-native-github ``` Followed up with ``` hg status -n --change . | xargs js1 prettier ``` Reviewed By: mdvacca Differential Revision: D16611291 fbshipit-source-id: 1157587416ec7603d1a59e1fad6a821f1f57b952