Skip to content

Commit cd89016

Browse files
corbtfacebook-github-bot-5
authored andcommitted
PixelRatio.pixel()
Summary: This implements #5073. It adds a static method `PixelRatio.pixel()` which returns the smallest drawable line width, primarily for use in styles. It also updates the example apps to use the new function. Closes facebook/react-native#5076 Reviewed By: svcscm Differential Revision: D2799849 Pulled By: nicklockwood fb-gh-sync-id: b83a77790601fe882affbf65531114e7c5cf4bdf
1 parent 78c6e41 commit cd89016

15 files changed

Lines changed: 60 additions & 49 deletions

File tree

Examples/Movies/MovieCell.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
var React = require('react-native');
1919
var {
2020
Image,
21-
PixelRatio,
2221
Platform,
2322
StyleSheet,
2423
Text,
@@ -99,8 +98,7 @@ var styles = StyleSheet.create({
9998
},
10099
cellBorder: {
101100
backgroundColor: 'rgba(0, 0, 0, 0.1)',
102-
// Trick to get the thinest line the device can display
103-
height: 1 / PixelRatio.get(),
101+
height: StyleSheet.hairlineWidth,
104102
marginLeft: 4,
105103
},
106104
});

Examples/Movies/MovieScreen.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
var React = require('react-native');
1919
var {
2020
Image,
21-
PixelRatio,
2221
ScrollView,
2322
StyleSheet,
2423
Text,
@@ -152,7 +151,7 @@ var styles = StyleSheet.create({
152151
},
153152
separator: {
154153
backgroundColor: 'rgba(0, 0, 0, 0.1)',
155-
height: 1 / PixelRatio.get(),
154+
height: StyleSheet.hairlineWidth,
156155
marginVertical: 10,
157156
},
158157
castTitle: {

Examples/UIExplorer/Navigator/BreadcrumbNavSample.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
var React = require('react-native');
1717
var {
18-
PixelRatio,
1918
Navigator,
2019
StyleSheet,
2120
ScrollView,
@@ -131,7 +130,7 @@ var styles = StyleSheet.create({
131130
button: {
132131
backgroundColor: 'white',
133132
padding: 15,
134-
borderBottomWidth: 1 / PixelRatio.get(),
133+
borderBottomWidth: StyleSheet.hairlineWidth,
135134
borderBottomColor: '#CDCDCD',
136135
},
137136
buttonText: {

Examples/UIExplorer/Navigator/JumpingNavSample.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
var React = require('react-native');
1717
var {
1818
Navigator,
19-
PixelRatio,
2019
StyleSheet,
2120
ScrollView,
2221
TabBarIOS,
@@ -185,7 +184,7 @@ var styles = StyleSheet.create({
185184
button: {
186185
backgroundColor: 'white',
187186
padding: 15,
188-
borderBottomWidth: 1 / PixelRatio.get(),
187+
borderBottomWidth: StyleSheet.hairlineWidth,
189188
borderBottomColor: '#CDCDCD',
190189
},
191190
buttonText: {

Examples/UIExplorer/Navigator/NavigationBarSample.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
var React = require('react-native');
1818
var {
19-
PixelRatio,
2019
Navigator,
2120
ScrollView,
2221
StyleSheet,
@@ -164,7 +163,7 @@ var styles = StyleSheet.create({
164163
button: {
165164
backgroundColor: 'white',
166165
padding: 15,
167-
borderBottomWidth: 1 / PixelRatio.get(),
166+
borderBottomWidth: StyleSheet.hairlineWidth,
168167
borderBottomColor: '#CDCDCD',
169168
},
170169
buttonText: {

Examples/UIExplorer/Navigator/NavigatorExample.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
var React = require('react-native');
1717
var {
1818
Navigator,
19-
PixelRatio,
2019
ScrollView,
2120
StyleSheet,
2221
Text,
@@ -190,7 +189,7 @@ var styles = StyleSheet.create({
190189
button: {
191190
backgroundColor: 'white',
192191
padding: 15,
193-
borderBottomWidth: 1 / PixelRatio.get(),
192+
borderBottomWidth: StyleSheet.hairlineWidth,
194193
borderBottomColor: '#CDCDCD',
195194
},
196195
buttonText: {

Examples/UIExplorer/NavigatorIOSExample.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ var ViewExample = require('./ViewExample');
2020
var createExamplePage = require('./createExamplePage');
2121
var {
2222
AlertIOS,
23-
PixelRatio,
2423
ScrollView,
2524
StyleSheet,
2625
Text,
@@ -227,7 +226,7 @@ var styles = StyleSheet.create({
227226
},
228227
line: {
229228
backgroundColor: '#bbbbbb',
230-
height: 1 / PixelRatio.get(),
229+
height: StyleSheet.hairlineWidth,
231230
},
232231
row: {
233232
backgroundColor: 'white',
@@ -236,7 +235,7 @@ var styles = StyleSheet.create({
236235
paddingVertical: 15,
237236
},
238237
separator: {
239-
height: 1 / PixelRatio.get(),
238+
height: StyleSheet.hairlineWidth,
240239
backgroundColor: '#bbbbbb',
241240
marginLeft: 15,
242241
},

Examples/UIExplorer/TouchableExample.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,15 +229,15 @@ var styles = StyleSheet.create({
229229
logBox: {
230230
padding: 20,
231231
margin: 10,
232-
borderWidth: 1 / PixelRatio.get(),
232+
borderWidth: StyleSheet.hairlineWidth,
233233
borderColor: '#f0f0f0',
234234
backgroundColor: '#f9f9f9',
235235
},
236236
eventLogBox: {
237237
padding: 10,
238238
margin: 10,
239239
height: 120,
240-
borderWidth: 1 / PixelRatio.get(),
240+
borderWidth: StyleSheet.hairlineWidth,
241241
borderColor: '#f0f0f0',
242242
backgroundColor: '#f9f9f9',
243243
},

Examples/UIExplorer/UIExplorerListBase.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
var React = require('react-native');
1919
var {
2020
ListView,
21-
PixelRatio,
2221
StyleSheet,
2322
Text,
2423
TextInput,
@@ -159,7 +158,7 @@ var styles = StyleSheet.create({
159158
paddingVertical: 8,
160159
},
161160
separator: {
162-
height: 1 / PixelRatio.get(),
161+
height: StyleSheet.hairlineWidth,
163162
backgroundColor: '#bbbbbb',
164163
marginLeft: 15,
165164
},

Examples/UIExplorer/XHRExample.android.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
var React = require('react-native');
1919
var {
20-
PixelRatio,
2120
ProgressBarAndroid,
2221
StyleSheet,
2322
Text,
@@ -312,7 +311,7 @@ var styles = StyleSheet.create({
312311
flexDirection: 'row',
313312
paddingVertical: 8,
314313
alignItems: 'center',
315-
borderBottomWidth: 1 / PixelRatio.get(),
314+
borderBottomWidth: StyleSheet.hairlineWidth,
316315
borderBottomColor: 'grey',
317316
},
318317
textButton: {

0 commit comments

Comments
 (0)