forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYellowBoxListRow.js
More file actions
100 lines (89 loc) · 2.55 KB
/
YellowBoxListRow.js
File metadata and controls
100 lines (89 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
'use strict';
const React = require('React');
const StyleSheet = require('StyleSheet');
const Text = require('Text');
const YellowBoxPressable = require('YellowBoxPressable');
const View = require('View');
const YellowBoxCategory = require('YellowBoxCategory');
const YellowBoxStyle = require('YellowBoxStyle');
const YellowBoxWarning = require('YellowBoxWarning');
import type {Category} from 'YellowBoxCategory';
type Props = $ReadOnly<{|
category: Category,
warnings: $ReadOnlyArray<YellowBoxWarning>,
onPress: (category: Category) => void,
|}>;
class YellowBoxListRow extends React.Component<Props> {
static GUTTER = StyleSheet.hairlineWidth;
static HEIGHT = 48;
shouldComponentUpdate(nextProps: Props): boolean {
const prevProps = this.props;
return (
prevProps.category !== nextProps.category ||
prevProps.onPress !== nextProps.onPress ||
prevProps.warnings.length !== nextProps.warnings.length ||
prevProps.warnings.some(
(prevWarning, index) => prevWarning !== nextProps[index],
)
);
}
render(): React.Node {
const {warnings} = this.props;
return (
<YellowBoxPressable onPress={this._handlePress} style={styles.root}>
<View style={styles.content}>
{warnings.length < 2 ? null : (
<Text style={styles.metaText}>{'(' + warnings.length + ') '}</Text>
)}
<Text numberOfLines={2} style={styles.bodyText}>
{YellowBoxCategory.render(
warnings[warnings.length - 1].message,
styles.substitutionText,
)}
</Text>
</View>
</YellowBoxPressable>
);
}
_handlePress = () => {
this.props.onPress(this.props.category);
};
}
const styles = StyleSheet.create({
root: {
height: YellowBoxListRow.HEIGHT,
justifyContent: 'center',
marginTop: YellowBoxListRow.GUTTER,
paddingHorizontal: 12,
},
content: {
alignItems: 'flex-start',
flexDirection: 'row',
},
bodyText: {
color: YellowBoxStyle.getTextColor(1),
flex: 1,
fontSize: 14,
includeFontPadding: false,
lineHeight: 18,
},
metaText: {
color: YellowBoxStyle.getTextColor(0.5),
fontSize: 14,
includeFontPadding: false,
lineHeight: 18,
},
substitutionText: {
color: YellowBoxStyle.getTextColor(0.6),
},
});
module.exports = YellowBoxListRow;