Skip to content

Commit 071506f

Browse files
Abbondanzofacebook-github-bot
authored andcommitted
Add tinted vector drawable example to RNTester (facebook#48541)
Summary: Pull Request resolved: facebook#48541 Shows how to use tintColor in conjunction with new XML file format, and serves as a good E2E test bench to ensure that drawables don't accidentally reuse the same state (if the underlying implementation isn't careful enough to call `buildCopy`, both icons will render red) Changelog: [Internal] Reviewed By: NickGerleman Differential Revision: D64136753 fbshipit-source-id: 3bd0933e587364425ac14a0635690d4b274a55fe
1 parent 9b646c8 commit 071506f

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

packages/rn-tester/js/examples/Image/ImageExample.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -612,28 +612,25 @@ class OnPartialLoadExample extends React.Component<
612612
}
613613
}
614614

615-
type VectorDrawableExampleState = {||};
616-
617-
type VectorDrawableExampleProps = $ReadOnly<{||}>;
618-
619-
class VectorDrawableExample extends React.Component<
620-
VectorDrawableExampleProps,
621-
VectorDrawableExampleState,
622-
> {
623-
state: VectorDrawableExampleState = {};
624-
625-
render(): React.Node {
626-
const isEnabled = ReactNativeFeatureFlags.loadVectorDrawablesOnImages();
627-
return (
628-
<View style={styles.flex}>
629-
<RNTesterText>Enabled: {isEnabled ? 'true' : 'false'}</RNTesterText>
630-
<View style={styles.vectorDrawableRow}>
631-
<Image source={{uri: 'ic_android'}} style={styles.vectorDrawable} />
632-
</View>
615+
const VectorDrawableExample = () => {
616+
const isEnabled = ReactNativeFeatureFlags.loadVectorDrawablesOnImages();
617+
return (
618+
<View style={styles.flex} testID="vector-drawable-example">
619+
<RNTesterText>Enabled: {isEnabled ? 'true' : 'false'}</RNTesterText>
620+
<View style={styles.horizontal}>
621+
<Image
622+
source={require('../../assets/ic_android.xml')}
623+
style={styles.vectorDrawable}
624+
/>
625+
<Image
626+
source={require('../../assets/ic_android.xml')}
627+
style={styles.vectorDrawable}
628+
tintColor="red"
629+
/>
633630
</View>
634-
);
635-
}
636-
}
631+
</View>
632+
);
633+
};
637634

638635
function CacheControlAndroidExample(): React.Node {
639636
const [reload, setReload] = React.useState(0);
@@ -934,10 +931,6 @@ const styles = StyleSheet.create({
934931
boxShadow: '80px 0px 10px 0px hotpink',
935932
transform: 'rotate(-15deg)',
936933
},
937-
vectorDrawableRow: {
938-
flexDirection: 'row',
939-
gap: 8,
940-
},
941934
vectorDrawable: {
942935
height: 64,
943936
width: 64,
@@ -1763,6 +1756,7 @@ exports.examples = [
17631756
},
17641757
{
17651758
title: 'Vector Drawable',
1759+
name: 'vector-drawable',
17661760
description:
17671761
'Demonstrating an example of loading a vector drawable asset by name',
17681762
render: function (): React.Node {

0 commit comments

Comments
 (0)