Skip to content
This repository was archived by the owner on Mar 10, 2023. It is now read-only.

Commit 1cd5bd8

Browse files
committed
new stuff
1 parent 42645ef commit 1cd5bd8

File tree

8 files changed

+92
-58
lines changed

8 files changed

+92
-58
lines changed

components/ActionSheet.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22

3-
import Cell from './Cell';
3+
import Cell, { CELL_MIN_HEIGHT } from './Cell';
44
import CellGroup from './CellGroup';
55

66
import theme from '../lib/theme';
@@ -22,8 +22,9 @@ export const ActionItem = function(props) {
2222
return <View {...props} />
2323
}
2424

25-
const BORDER_RADIUS = theme.isIOS ? theme.radius : 0;
26-
const MARGIN = theme.isIOS ? theme.margin : 0;
25+
const BORDER_RADIUS = theme.value(theme.radius, 0);
26+
const MARGIN = theme.value(theme.margin, 0);
27+
const STATUS_BAR_HEIGHT = 20;
2728

2829
class ActionSheet extends React.Component {
2930
static defaultProps = {
@@ -180,13 +181,23 @@ class ActionSheet extends React.Component {
180181
this.close(item.props.onPress);
181182
};
182183

184+
let isDisabled = false;
183185
const tintColor = item.props.destructive ? theme.color.danger : item.props.tintColor;
184186

187+
if (item.props.disabled) {
188+
if (typeof item.props.disabled === 'function') {
189+
isDisabled = item.props.disabled();
190+
} else {
191+
isDisabled = item.props.disabled;
192+
}
193+
}
194+
185195
return (
186196
<View key={'action-item-' + i}>
187197
<Cell
188198
{...item.props}
189199
onPress={item.props.onPress ? itemOnPress : null}
200+
disabled={isDisabled}
190201
style={[
191202
item.props.backgroundColor && { backgroundColor: item.props.backgroundColor },
192203
isFirstChild && styles.borderTopRadius,
@@ -264,7 +275,7 @@ const styles = StyleSheet.create({
264275
backgroundColor: theme.color.white
265276
},
266277
title: {
267-
fontSize: theme.isIOS ? theme.font.xsmall : theme.font.small,
278+
fontSize: theme.value(theme.font.xsmall, theme.font.small),
268279
color: theme.color.muted
269280
},
270281
actionsContainer: {
@@ -280,7 +291,7 @@ const styles = StyleSheet.create({
280291
backgroundColor: theme.color.white
281292
},
282293
actionItemsList: {
283-
marginTop: theme.isIOS ? 68 : 48
294+
marginTop: theme.value(CELL_MIN_HEIGHT + STATUS_BAR_HEIGHT, CELL_MIN_HEIGHT)
284295
},
285296
cancelText: {
286297
textAlign: 'center',
@@ -290,12 +301,10 @@ const styles = StyleSheet.create({
290301
flex: 1
291302
},
292303
borderTopRadius: {
293-
borderTopRightRadius: BORDER_RADIUS,
294-
borderTopLeftRadius: BORDER_RADIUS,
304+
...theme.borderRadius.top
295305
},
296306
borderBottomRadius: {
297-
borderBottomRightRadius: BORDER_RADIUS,
298-
borderBottomLeftRadius: BORDER_RADIUS
307+
...theme.borderRadius.bottom
299308
}
300309
});
301310

components/Cell.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ import {
1111
Platform
1212
} from 'react-native';
1313

14-
const CELL_MIN_HEIGHT = 48;
14+
export const CELL_MIN_HEIGHT = 48;
1515
const ICON_DEFAULT_SIZE = 24;
1616
const TITLE_MIN_WIDTH = 98;
1717
const CORNER_MIN_WIDTH = theme.padding;
18-
const Touchable = theme.isIOS ? TouchableHighlight : TouchableNativeFeedback;
18+
const Touchable = theme.value(TouchableHighlight, TouchableNativeFeedback);
1919
let ANDROID_BACKGROUND = null;
2020

2121
if (theme.isAndroid) {
@@ -42,6 +42,7 @@ class Cell extends React.Component {
4242
selected: false,
4343
iconSelected: 'check-box',
4444
iconUnSelected: 'check-box-outline-blank',
45+
disabled: false,
4546
onSelect: () => null
4647
}
4748

@@ -60,7 +61,8 @@ class Cell extends React.Component {
6061
iconUnSelected: React.PropTypes.string,
6162
onSelect: React.PropTypes.func,
6263
onPress: React.PropTypes.func,
63-
onLongPress: React.PropTypes.func
64+
onLongPress: React.PropTypes.func,
65+
disabled: React.PropTypes.bool
6466
}
6567

6668
constructor(props) {
@@ -273,9 +275,17 @@ class Cell extends React.Component {
273275
<Touchable
274276
background={theme.isAndroid && this.props.onPress ? ANDROID_BACKGROUND : null}
275277
onPress={this.props.onPress || isSelecting ? this.handleCellOnPress : null}
278+
disabled={this.props.disabled}
276279
onLongPress={this.props.onLongPress}
277280
>
278-
<View style={[ styles.container, this.props.style, this.props.selected && isSelecting ? styles.selectedContainer : null ]} >
281+
<View
282+
style={[
283+
styles.container,
284+
this.props.selected && isSelecting ? styles.selectedContainer : null,
285+
this.props.disabled && { opacity: 0.5 },
286+
this.props.style
287+
]}
288+
>
279289
{this.renderSelect()}
280290
<View
281291
style={[

components/CellGroup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const styles = StyleSheet.create({
9898
...theme.separator
9999
},
100100
header: {
101-
paddingVertical: theme.isIOS ? theme.padding : theme.padding / 2,
101+
paddingVertical: theme.value(theme.padding, theme.padding / 2),
102102
paddingHorizontal: theme.padding * 1.5
103103
},
104104
headerText: {

components/CellInput.js

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,46 @@ import {
99
TextInput
1010
} from 'react-native';
1111

12-
const BASE_HEIGHT = 23;
12+
const BASE_HEIGHT = 20;
13+
const OFFSET = theme.value(10, 4);
1314

1415
class CellInput extends React.Component {
1516
static defaultProps = {
1617
rows: 1,
17-
autoResize: false
18+
autoResize: false,
19+
minRows: 1
1820
}
1921

2022
static propTypes = {
2123
...TextInput.propTypes,
2224
rows: React.PropTypes.number,
25+
minRows: React.PropTypes.number,
2326
autoResize: React.PropTypes.bool
2427
}
2528

2629
constructor(props) {
2730
super(props);
2831

32+
let height = BASE_HEIGHT;
33+
34+
// autorize is not yet supported in android (?)
35+
if (this.props.multiline && (!this.props.autoResize || theme.isAndroid)) {
36+
height = Math.max(BASE_HEIGHT * this.props.rows, BASE_HEIGHT * this.props.minRows);
37+
}
38+
2939
this.state = {
30-
rows: this.props.rows
40+
height
3141
}
3242
}
3343

3444
handleOnContentSizeChange = (e) => {
3545
const contentHeight = e.nativeEvent.contentSize.height;
3646

37-
if (this.props.autoResize) {
47+
// autorize is not yet supported in android (?)
48+
if (this.props.autoResize && theme.isIOS) {
3849
if ((contentHeight - contentHeight % BASE_HEIGHT) / BASE_HEIGHT < this.props.rows) {
39-
this.setNativeProps({
40-
height: contentHeight
50+
this.setState({
51+
height: Math.max(BASE_HEIGHT * this.props.minRows, contentHeight)
4152
});
4253
}
4354
}
@@ -56,22 +67,17 @@ class CellInput extends React.Component {
5667
}
5768

5869
renderTextInput() {
59-
const textInputStyle = this.props.multiline &&
60-
{
61-
// paddingBottom: theme.padding,
62-
height: this.props.autoResize ? BASE_HEIGHT : BASE_HEIGHT * this.props.rows
63-
}
64-
6570
return (
6671
<TextInput
6772
ref={component => this._textInput = component}
6873
clearButtonMode="while-editing"
6974
selectionColor={theme.color.info}
75+
placeholderTextColor={this.props.placeholderTextColor || theme.color.muted}
76+
autoCapitalize="sentences"
7077
{...this.props}
71-
style={[ styles.textInput, textInputStyle, this.props.style ]}
78+
style={[ styles.textInput, { height: this.state.height + OFFSET } ]}
7279
onContentSizeChange={this.handleOnContentSizeChange}
7380
placeholder={this.props.multiline === true ? this.props.title || this.props.placeholder : this.props.placeholder}
74-
placeholderTextColor={theme.color.muted}
7581
underlineColorAndroid="transparent"
7682
/>
7783
);
@@ -82,8 +88,10 @@ class CellInput extends React.Component {
8288
<Cell
8389
icon={this.props.icon}
8490
tintColor={this.props.tintColor}
91+
disclosure={this.props.disclosure}
92+
contentPosition="top"
8593
title={!this.props.multiline && this.props.title}
86-
style={this.props.editable === false && styles.inputDisabled}
94+
style={[ this.props.editable === false && styles.inputDisabled, this.props.style ]}
8795
>
8896
{this.renderTextInput()}
8997
</Cell>
@@ -95,6 +103,7 @@ const styles = StyleSheet.create({
95103
textInput: {
96104
fontSize: theme.font.medium,
97105
textAlign: 'left',
106+
textAlignVertical: 'top',
98107
flex: 1,
99108
height: BASE_HEIGHT,
100109
padding: 0

components/CellSwipeable.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import React from 'react';
33
import Cell from './Cell';
44

55
import {
6-
View,
7-
StyleSheet
6+
View
87
} from 'react-native';
98

109
// https://raw.githubusercontent.com/facebook/react-native/master/Libraries/Experimental/SwipeableRow/SwipeableRow.js

components/SelectList.js

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ class SelectList extends React.Component {
261261
}
262262

263263
return (
264-
<View style={this.props.modal === true ? styles.headerView : styles.separator} />
264+
<View style={styles.separator} />
265265
);
266266
}
267267

@@ -275,13 +275,14 @@ class SelectList extends React.Component {
275275
}
276276

277277
renderListView() {
278-
if (!this.props.data) {
278+
if (!this.props.data || (this.props.realm && this.props.data && this.props.data.length === 0)) {
279279
return (
280280
<View>
281281
{this.renderHeader()}
282-
<Cell>
283-
<Text style={styles.placeholder}>{this.props.placeholder ? this.props.placeholder : DEFAULT_PLACEHOLDER }</Text>
284-
</Cell>
282+
<Cell
283+
title={this.props.placeholder || DEFAULT_PLACEHOLDER }
284+
tintColor={theme.color.muted}
285+
/>
285286
<View style={styles.separator} />
286287
{this.props.renderFooter && this.renderFooter()}
287288
</View>
@@ -339,20 +340,7 @@ const styles = StyleSheet.create({
339340
right: 0,
340341
bottom: 0,
341342
backgroundColor: BACKGROUND_COLOR,
342-
elevation: 5,
343-
zIndex: 10
344-
},
345-
placeholder: {
346-
flex: 1,
347-
fontSize: theme.font.small,
348-
fontWeight: '500',
349-
color: theme.color.muted
350-
},
351-
headerView: {
352-
...theme.border.top,
353-
...theme.border.bottom,
354-
height: 5,
355-
backgroundColor: BACKGROUND_COLOR
343+
elevation: 5
356344
},
357345
headerText: {
358346
fontSize: theme.font.xsmall,

components/TagsInput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ const styles = StyleSheet.create({
244244
},
245245
textInput: {
246246
fontSize: theme.font.medium,
247-
height: theme.isIOS ? 20 : 25,
247+
height: theme.value(20, 25),
248248
padding: 0
249249
},
250250
textInputFocus: {

lib/theme.js

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,42 @@ const colors = {
2424
lightGrey: '#e9e9e9'
2525
};
2626

27-
const borderWidth = StyleSheet.hairlineWidth; // 1 / PixelRatio.get();
27+
const value = (ios = null, android = null) => {
28+
return Platform.select({
29+
ios,
30+
android
31+
});
32+
};
33+
34+
const borderWidth = StyleSheet.hairlineWidth;
35+
const radius = value(5, 2);
36+
const padding = value(10, 16);
37+
const margin = value(10, 8);
2838

2939
const borders = {};
40+
const borderRadius = {};
41+
3042
['Bottom', 'Top', 'Left', 'Right'].forEach((key) => {
3143
const keyName = key === 'all' ? '' : key;
3244

3345
borders[key.toLowerCase()] = {
3446
['border' + keyName + 'Width']: borderWidth,
3547
['border' + keyName + 'Color']: colors.border
3648
};
49+
50+
borderRadius[key.toLowerCase()] = {
51+
['border' + keyName + 'RightRadius']: radius,
52+
['border' + keyName + 'LeftRadius']: radius,
53+
};
3754
});
3855

3956
export default theme = {
4057
border: { ...borders },
58+
borderRadius: { ...borderRadius },
4159
separator: {
4260
backgroundColor: colors.border,
4361
height: borderWidth
4462
},
45-
radius: Platform.OS === 'ios' ? 5 : 2,
46-
padding: Platform.OS === 'ios' ? 10 : 16,
47-
margin: Platform.OS === 'ios' ? 10 : 8,
4863
color: colors,
4964
font: {
5065
xxsmall: 10,
@@ -57,7 +72,6 @@ export default theme = {
5772
},
5873
background: colors.light,
5974
backgroundDarker: colors.lightGrey,
60-
borderWidth: borderWidth,
6175
borderColor: colors.border,
6276
iconWidth: 29,
6377
styles: {
@@ -68,6 +82,11 @@ export default theme = {
6882
alignItems: 'flex-end'
6983
}
7084
},
71-
isAndroid: Platform.OS === 'android',
72-
isIOS: Platform.OS === 'ios'
85+
isAndroid: value(false, true),
86+
isIOS: value(true, false),
87+
borderWidth,
88+
radius,
89+
padding,
90+
margin,
91+
value
7392
};

0 commit comments

Comments
 (0)