-
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.
Fix Native Rotation Android (#18872)
Summary: Fixes #14161 Android crashes in some cases if an animated transform config contains a string value, like a rotation. This PR fixes that by ensuring all values sent to the native side are doubles. It adds `__transformDataType` to AnimatedTransform.js. Added integration test `ReactAndroid/src/androidText/js/AnimatedTransformTestModule.js` This test fails with the following error `INSTRUMENTATION_RESULT: longMsg=java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Double`, if the changes to AnimatedTransform.js are reverted. [Android] [Fixed] - Fixes Android crash on animated style with string rotation Pull Request resolved: #18872 Differential Revision: D13894676 Pulled By: cpojer fbshipit-source-id: 297e8132563460802e53f3ac551c3ba9ed943736
- Loading branch information
1 parent
0269729
commit e405e84
Showing
6 changed files
with
160 additions
and
16 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
55 changes: 55 additions & 0 deletions
55
ReactAndroid/src/androidTest/java/com/facebook/react/tests/AnimatedTransformTest.java
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,55 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
package com.facebook.react.tests; | ||
|
||
import android.view.View; | ||
|
||
|
||
import com.facebook.react.testing.ReactInstanceSpecForTest; | ||
import com.facebook.react.testing.StringRecordingModule; | ||
import com.facebook.react.bridge.JavaScriptModule; | ||
import com.facebook.react.testing.ReactAppInstrumentationTestCase; | ||
import com.facebook.react.testing.ReactTestHelper; | ||
|
||
/** | ||
* Integration test for {@code removeClippedSubviews} property that verify correct scrollview | ||
* behavior | ||
*/ | ||
public class AnimatedTransformTest extends ReactAppInstrumentationTestCase { | ||
|
||
private StringRecordingModule mStringRecordingModule; | ||
|
||
@Override | ||
protected String getReactApplicationKeyUnderTest() { | ||
return "AnimatedTransformTestApp"; | ||
} | ||
|
||
@Override | ||
protected ReactInstanceSpecForTest createReactInstanceSpecForTest() { | ||
mStringRecordingModule = new StringRecordingModule(); | ||
return super.createReactInstanceSpecForTest() | ||
.addNativeModule(mStringRecordingModule); | ||
} | ||
|
||
public void testAnimatedRotation() { | ||
waitForBridgeAndUIIdle(); | ||
|
||
View button = ReactTestHelper.getViewWithReactTestId( | ||
getActivity().getRootView(), | ||
"TouchableOpacity"); | ||
|
||
// Tap the button which triggers the animated transform containing the | ||
// rotation strings. | ||
createGestureGenerator().startGesture(button).endGesture(); | ||
waitForBridgeAndUIIdle(); | ||
|
||
// The previous cast error will prevent it from getting here | ||
assertEquals(2, mStringRecordingModule.getCalls().size()); | ||
} | ||
|
||
} |
81 changes: 81 additions & 0 deletions
81
ReactAndroid/src/androidTest/js/AnimatedTransformTestModule.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,81 @@ | ||
/** | ||
* Copyright (c) 2013-present, Facebook, Inc. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @providesModule AnimatedTransformTestModule | ||
*/ | ||
|
||
'use strict'; | ||
|
||
var BatchedBridge = require('BatchedBridge'); | ||
var React = require('React'); | ||
var StyleSheet = require('StyleSheet'); | ||
var View = require('View'); | ||
var TouchableOpacity = require('TouchableOpacity'); | ||
var Text = require('Text'); | ||
var RecordingModule = require('NativeModules').Recording; | ||
|
||
const styles = StyleSheet.create({ | ||
base: { | ||
width: 200, | ||
height: 200, | ||
backgroundColor: 'red', | ||
transform: [{rotate: '0deg'}], | ||
}, | ||
transformed: { | ||
transform: [{rotate: '45deg'}], | ||
}, | ||
}); | ||
|
||
/** | ||
* This app presents a TouchableOpacity which was the simplest way to | ||
* demonstrate this issue. Tapping the TouchableOpacity causes an animated | ||
* transform to be created for the rotation property. Since the property isn't | ||
* animated itself, it comes through as a static property, but static properties | ||
* can't currently handle strings which causes a string->double cast exception. | ||
*/ | ||
class AnimatedTransformTestApp extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
this.toggle = this.toggle.bind(this); | ||
} | ||
|
||
state = { | ||
flag: false, | ||
}; | ||
|
||
toggle() { | ||
this.setState({ | ||
flag: !this.state.flag, | ||
}); | ||
} | ||
|
||
render() { | ||
// Using this to verify if its fixed. | ||
RecordingModule.record('render'); | ||
|
||
return ( | ||
<View style={StyleSheet.absoluteFill}> | ||
<TouchableOpacity | ||
onPress={this.toggle} | ||
testID="TouchableOpacity" | ||
style={[styles.base, this.state.flag ? styles.transformed : null]}> | ||
<Text>TouchableOpacity</Text> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
var AnimatedTransformTestModule = { | ||
AnimatedTransformTestApp: AnimatedTransformTestApp, | ||
}; | ||
|
||
BatchedBridge.registerCallableModule( | ||
'AnimatedTransformTestModule', | ||
AnimatedTransformTestModule | ||
); | ||
|
||
module.exports = AnimatedTransformTestModule; |
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