Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.76-stable] Fix accessible prop for image #2330

Merged
Merged
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
5 changes: 5 additions & 0 deletions packages/react-native/Libraries/Image/RCTImageView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,11 @@ - (RCTPlatformView *)reactAccessibilityElement
return _imageView;
}

- (NSCell *)reactAccessibilityElementCell
{
return _imageView.cell;
}

- (NSColor *)tintColor
{
return _imageView.tintColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ - (RCTPlatformView *)view // [macOS]
return [[RCTImageView alloc] initWithBridge:self.bridge];
}

#if TARGET_OS_OSX // [macOS
// setting accessibilityElement on NSImageView has no effect, must be set on NSImageCell
RCT_REMAP_VIEW_PROPERTY(accessible, reactAccessibilityElementCell.accessibilityElement, BOOL)
#endif // macOS]
RCT_EXPORT_VIEW_PROPERTY(blurRadius, CGFloat)
RCT_EXPORT_VIEW_PROPERTY(capInsets, UIEdgeInsets)
RCT_REMAP_VIEW_PROPERTY(defaultSource, defaultImage, UIImage)
Expand Down
28 changes: 26 additions & 2 deletions packages/rn-tester/js/examples/Image/ImageExample.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const {
Image,
ImageBackground,
StyleSheet,
Switch, // [macOS]
Text,
View,
} = require('react-native');
Expand Down Expand Up @@ -625,6 +626,21 @@ class VectorDrawableExample extends React.Component<
}
}

// [macOS add switch to toggle the value of the accessible prop
const AccessibilityExample = () => {
const [isAccessible, setIsAccessible] = React.useState(true);
return (
<>
<View style={styles.switch}>
<Text>Set acccessible:</Text>
<Switch value={isAccessible} onValueChange={setIsAccessible} />
</View>
<Image accessible={isAccessible} source={fullImage} style={styles.base} />
</>
);
};
// macOS]

const fullImage: ImageSource = {
uri: IMAGE2,
};
Expand Down Expand Up @@ -850,6 +866,12 @@ const styles = StyleSheet.create({
boxShadow: '80px 0px 10px 0px hotpink',
transform: 'rotate(-15deg)',
},
// [macOS
switch: {
flexDirection: 'row',
alignItems: 'center',
},
// macOS]
});

exports.displayName = (undefined: ?string);
Expand Down Expand Up @@ -1527,14 +1549,16 @@ exports.examples = [
);
},
},
// [macOS
{
title: 'Accessibility',
description:
('If the `accessible` (boolean) prop is set to True, the image will be indicated as an accessbility element.': string),
('If the `accessible` (boolean) prop is set to True, the image will be indicated as an accessbility element. If the `accessible` (boolean) prop is set to False, the image will not be indicated as an accessbility element.': string),
render: function (): React.Node {
return <Image accessible source={fullImage} style={styles.base} />;
return <AccessibilityExample />;
},
},
// macOS]
{
title: 'Accessibility Label',
description:
Expand Down