Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface PressableAndroidRippleConfig {
borderless?: null | boolean | undefined;
radius?: null | number | undefined;
foreground?: null | boolean | undefined;
alpha?: null | number | undefined;
}

export interface PressableProps
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
*/

import {expectRendersMatchingSnapshot} from '../../../Utilities/ReactNativeTestTools';
import Platform from '../../../Utilities/Platform';
import {PlatformColor} from '../../../StyleSheet/PlatformColorValueTypes';
import View from '../../View/View';
import Pressable from '../Pressable';
import * as React from 'react';
Expand Down Expand Up @@ -92,3 +94,65 @@ describe('<Pressable disabled={true} accessibilityState={{disabled: false}} />',
);
});
});

describe('<Pressable android_ripple /> on Android', () => {
let originalOS: string;

beforeEach(() => {
originalOS = Platform.OS;
/* $FlowFixMe[incompatible-type] */
Platform.OS = 'android';
});

afterEach(() => {
/* $FlowFixMe[incompatible-type] */
Platform.OS = originalOS;
});

it('should set nativeBackgroundAndroid with numeric color and alpha', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable android_ripple={{color: '#FF0000', alpha: 0.5}}>
<View />
</Pressable>
),
() => {
jest.dontMock('../Pressable');
},
);
});

it('should set nativeBackgroundAndroid with PlatformColor and alpha', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable
android_ripple={{color: PlatformColor('?attr/colorAccent'), alpha: 0.3}}>
<View />
</Pressable>
),
() => {
jest.dontMock('../Pressable');
},
);
});

it('should not crash with an unresolvable PlatformColor', async () => {
await expectRendersMatchingSnapshot(
'Pressable',
() => (
<Pressable
android_ripple={{
color: PlatformColor('?attr/doesNotExist'),
alpha: 0.5,
}}>
<View />
</Pressable>
),
() => {
jest.dontMock('../Pressable');
},
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,292 @@ exports[`<Pressable /> should render as expected: should deep render when not mo
</View>
`;

exports[`<Pressable android_ripple /> on Android should not crash with an unresolvable PlatformColor: should deep render when mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
nativeBackgroundAndroid={
Object {
"alpha": 0.5,
"borderless": false,
"color": Object {
"semantic": Array [
"?attr/doesNotExist",
],
},
"rippleRadius": undefined,
"type": "RippleAndroid",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View />
</View>
`;

exports[`<Pressable android_ripple /> on Android should not crash with an unresolvable PlatformColor: should deep render when not mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
nativeBackgroundAndroid={
Object {
"alpha": 0.5,
"borderless": false,
"color": Object {
"semantic": Array [
"?attr/doesNotExist",
],
},
"rippleRadius": undefined,
"type": "RippleAndroid",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View />
</View>
`;

exports[`<Pressable android_ripple /> on Android should set nativeBackgroundAndroid with PlatformColor and alpha: should deep render when mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
nativeBackgroundAndroid={
Object {
"alpha": 0.3,
"borderless": false,
"color": Object {
"semantic": Array [
"?attr/colorAccent",
],
},
"rippleRadius": undefined,
"type": "RippleAndroid",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View />
</View>
`;

exports[`<Pressable android_ripple /> on Android should set nativeBackgroundAndroid with PlatformColor and alpha: should deep render when not mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
nativeBackgroundAndroid={
Object {
"alpha": 0.3,
"borderless": false,
"color": Object {
"semantic": Array [
"?attr/colorAccent",
],
},
"rippleRadius": undefined,
"type": "RippleAndroid",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View />
</View>
`;

exports[`<Pressable android_ripple /> on Android should set nativeBackgroundAndroid with numeric color and alpha: should deep render when mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
nativeBackgroundAndroid={
Object {
"alpha": 0.5,
"borderless": false,
"color": -65536,
"rippleRadius": undefined,
"type": "RippleAndroid",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View />
</View>
`;

exports[`<Pressable android_ripple /> on Android should set nativeBackgroundAndroid with numeric color and alpha: should deep render when not mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Object {
"busy": undefined,
"checked": undefined,
"disabled": undefined,
"expanded": undefined,
"selected": undefined,
}
}
accessibilityValue={
Object {
"max": undefined,
"min": undefined,
"now": undefined,
"text": undefined,
}
}
accessible={true}
collapsable={false}
focusable={true}
nativeBackgroundAndroid={
Object {
"alpha": 0.5,
"borderless": false,
"color": -65536,
"rippleRadius": undefined,
"type": "RippleAndroid",
}
}
onBlur={[Function]}
onClick={[Function]}
onFocus={[Function]}
onResponderGrant={[Function]}
onResponderMove={[Function]}
onResponderRelease={[Function]}
onResponderTerminate={[Function]}
onResponderTerminationRequest={[Function]}
onStartShouldSetResponder={[Function]}
>
<View />
</View>
`;

exports[`<Pressable disabled={true} /> should be disabled when disabled is true: should deep render when mocked (please verify output manually) 1`] = `
<View
accessibilityState={
Expand Down
Loading