Skip to content

Commit 41eb2da

Browse files
ignacioolafacebook-github-bot
authored andcommitted
Fix inline styles warning in Libraries (#22161)
Summary: Fixes `react-native/no-inline-styles` eslint warnings in the `Libraries` module. Pull Request resolved: #22161 Differential Revision: D12946899 Pulled By: TheSavior fbshipit-source-id: c97ffa50dd90529dabf30a3d2cb09476acc568cb
1 parent 69213ee commit 41eb2da

File tree

3 files changed

+76
-46
lines changed

3 files changed

+76
-46
lines changed

Libraries/Components/Touchable/Touchable.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Platform = require('Platform');
1414
const Position = require('Position');
1515
const React = require('React');
1616
const ReactNative = require('ReactNative');
17+
const StyleSheet = require('StyleSheet');
1718
const TVEventHandler = require('TVEventHandler');
1819
const TouchEventUtils = require('fbjs/lib/TouchEventUtils');
1920
const UIManager = require('UIManager');
@@ -858,17 +859,25 @@ const Touchable = {
858859
return (
859860
<View
860861
pointerEvents="none"
861-
style={{
862-
position: 'absolute',
863-
borderColor: hexColor.slice(0, -2) + '55', // More opaque
864-
borderWidth: 1,
865-
borderStyle: 'dashed',
866-
backgroundColor: hexColor.slice(0, -2) + '0F', // Less opaque
867-
...debugHitSlopStyle,
868-
}}
862+
style={[
863+
styles.debug,
864+
{
865+
borderColor: hexColor.slice(0, -2) + '55', // More opaque
866+
backgroundColor: hexColor.slice(0, -2) + '0F', // Less opaque
867+
...debugHitSlopStyle,
868+
},
869+
]}
869870
/>
870871
);
871872
},
872873
};
873874

875+
const styles = StyleSheet.create({
876+
debug: {
877+
position: 'absolute',
878+
borderWidth: 1,
879+
borderStyle: 'dashed',
880+
},
881+
});
882+
874883
module.exports = Touchable;

Libraries/Experimental/WindowedListView.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,7 @@ class CellRenderer extends React.Component<CellProps> {
777777
if (DEBUG) {
778778
infoLog('render cell ' + this.props.rowIndex);
779779
const Text = require('Text');
780-
debug = (
781-
<Text style={{backgroundColor: 'lightblue'}}>
782-
Row: {this.props.rowIndex}
783-
</Text>
784-
);
780+
debug = <Text style={styles.debug}>Row: {this.props.rowIndex}</Text>;
785781
}
786782
const style = this._includeInLayoutLatch ? styles.include : styles.remove;
787783
return (
@@ -819,6 +815,9 @@ const styles = StyleSheet.create({
819815
right: -removedXOffset,
820816
opacity: DEBUG ? 0.1 : 0,
821817
},
818+
debug: {
819+
backgroundColor: 'lightblue',
820+
},
822821
});
823822

824823
module.exports = WindowedListView;

Libraries/Lists/VirtualizedList.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
954954
);
955955
if (this.props.debug) {
956956
return (
957-
<View style={{flex: 1}}>
957+
<View style={styles.debug}>
958958
{ret}
959959
{this._renderDebugOverlay()}
960960
</View>
@@ -1194,47 +1194,41 @@ class VirtualizedList extends React.PureComponent<Props, State> {
11941194
const windowLen = frameLast.offset + frameLast.length - windowTop;
11951195
const visTop = this._scrollMetrics.offset;
11961196
const visLen = this._scrollMetrics.visibleLength;
1197-
const baseStyle = {position: 'absolute', top: 0, right: 0};
1197+
11981198
return (
1199-
<View
1200-
style={{
1201-
...baseStyle,
1202-
bottom: 0,
1203-
width: 20,
1204-
borderColor: 'blue',
1205-
borderWidth: 1,
1206-
}}>
1199+
<View style={[styles.debugOverlayBase, styles.debugOverlay]}>
12071200
{framesInLayout.map((f, ii) => (
12081201
<View
12091202
key={'f' + ii}
1210-
style={{
1211-
...baseStyle,
1212-
left: 0,
1213-
top: f.offset * normalize,
1214-
height: f.length * normalize,
1215-
backgroundColor: 'orange',
1216-
}}
1203+
style={[
1204+
styles.debugOverlayBase,
1205+
styles.debugOverlayFrame,
1206+
{
1207+
top: f.offset * normalize,
1208+
height: f.length * normalize,
1209+
},
1210+
]}
12171211
/>
12181212
))}
12191213
<View
1220-
style={{
1221-
...baseStyle,
1222-
left: 0,
1223-
top: windowTop * normalize,
1224-
height: windowLen * normalize,
1225-
borderColor: 'green',
1226-
borderWidth: 2,
1227-
}}
1214+
style={[
1215+
styles.debugOverlayBase,
1216+
styles.debugOverlayFrameLast,
1217+
{
1218+
top: windowTop * normalize,
1219+
height: windowLen * normalize,
1220+
},
1221+
]}
12281222
/>
12291223
<View
1230-
style={{
1231-
...baseStyle,
1232-
left: 0,
1233-
top: visTop * normalize,
1234-
height: visLen * normalize,
1235-
borderColor: 'red',
1236-
borderWidth: 2,
1237-
}}
1224+
style={[
1225+
styles.debugOverlayBase,
1226+
styles.debugOverlayFrameVis,
1227+
{
1228+
top: visTop * normalize,
1229+
height: visLen * normalize,
1230+
},
1231+
]}
12381232
/>
12391233
</View>
12401234
);
@@ -1785,6 +1779,34 @@ const styles = StyleSheet.create({
17851779
horizontallyInverted: {
17861780
transform: [{scaleX: -1}],
17871781
},
1782+
debug: {
1783+
flex: 1,
1784+
},
1785+
debugOverlayBase: {
1786+
position: 'absolute',
1787+
top: 0,
1788+
right: 0,
1789+
},
1790+
debugOverlay: {
1791+
bottom: 0,
1792+
width: 20,
1793+
borderColor: 'blue',
1794+
borderWidth: 1,
1795+
},
1796+
debugOverlayFrame: {
1797+
left: 0,
1798+
backgroundColor: 'orange',
1799+
},
1800+
debugOverlayFrameLast: {
1801+
left: 0,
1802+
borderColor: 'green',
1803+
borderWidth: 2,
1804+
},
1805+
debugOverlayFrameVis: {
1806+
left: 0,
1807+
borderColor: 'red',
1808+
borderWidth: 2,
1809+
},
17881810
});
17891811

17901812
module.exports = VirtualizedList;

0 commit comments

Comments
 (0)