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

Commit 9c2c635

Browse files
committed
0.0.21
1 parent 6fe7cfd commit 9c2c635

File tree

6 files changed

+39
-17
lines changed

6 files changed

+39
-17
lines changed

components/ActionSheet.js

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ const TOP_OFFSET = 20;
2828
class ActionSheet extends React.Component {
2929
static defaultProps = {
3030
animated: true,
31-
mode: 'default'
31+
mode: 'default',
32+
cancelText: 'Cancel',
33+
destructive: false
3234
}
3335

3436
static propTypes = {
@@ -39,7 +41,10 @@ class ActionSheet extends React.Component {
3941
'default', // default
4042
'list'
4143
]),
42-
title: React.PropTypes.any
44+
title: React.PropTypes.any,
45+
cancelText: React.PropTypes.string,
46+
onCancelPress: React.PropTypes.func,
47+
destructive: React.PropTypes.bool
4348
}
4449

4550
constructor(props) {
@@ -121,6 +126,10 @@ class ActionSheet extends React.Component {
121126
this.animateToValue(0, this.props.onOpen);
122127
}
123128

129+
handleCancelOnPress = () => {
130+
this.close(this.props.onCancelPress);
131+
}
132+
124133
renderActionItems() {
125134
const children = React.Children.toArray(this.props.children);
126135

@@ -134,6 +143,14 @@ class ActionSheet extends React.Component {
134143
children.unshift(title);
135144
}
136145

146+
if (this.props.cancelText) {
147+
children.push(
148+
<ActionItem backgroundColor={theme.color.light} onPress={this.handleCancelOnPress} >
149+
<Text style={styles.cancelText} >{this.props.cancelText.toUpperCase()}</Text>
150+
</ActionItem>
151+
);
152+
}
153+
137154
return children.map((item, i) => {
138155

139156
const isFirstChild = i === 0;
@@ -155,8 +172,6 @@ class ActionSheet extends React.Component {
155172
</View>
156173
);
157174
} else {
158-
const title = item.props.destructive ? <Text style={styles.actionDestructiveText} >{item.props.title.toUpperCase()}</Text> : item.props.title;
159-
160175
const itemOnPress = () => {
161176
this.close(item.props.onPress);
162177
};
@@ -165,13 +180,13 @@ class ActionSheet extends React.Component {
165180
<View key={'action-item-' + i}>
166181
<Cell
167182
{...item.props}
168-
title={title}
169-
onPress={item.props.destructive || item.props.onPress ? itemOnPress : null}
183+
onPress={item.props.onPress && itemOnPress}
170184
style={[
171-
item.props.destructive ? styles.actionDestructive : item.props.backgroundColor && { backgroundColor: item.props.backgroundColor },
185+
item.props.backgroundColor && { backgroundColor: item.props.backgroundColor },
172186
isFirstChild ? styles.borderTopRadius : null,
173187
isLastChild ? styles.borderBottomRadius : null
174188
]}
189+
tintColor={item.props.destructive && theme.color.danger}
175190
/>
176191
{separator}
177192
</View>
@@ -232,15 +247,14 @@ const styles = StyleSheet.create({
232247
backgroundColor: theme.color.white
233248
},
234249

235-
actionDestructive: {
250+
cancelContainer: {
236251
backgroundColor: theme.color.light
237252
},
238-
actionDestructiveText: {
253+
cancelText: {
239254
textAlign: 'center',
240255
fontSize: theme.font.small,
241256
fontWeight: '600',
242-
color: theme.color.muted,
243-
flex: 1
257+
color: theme.color.muted
244258
},
245259
borderTopRadius: {
246260
borderTopRightRadius: theme.radius,

components/Cell.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,7 @@ const styles = StyleSheet.create({
181181
textAlign: 'right'
182182
},
183183
titleContainer: {
184-
minWidth: TITLE_MIN_WIDTH,
185-
// flex: 1,
184+
minWidth: TITLE_MIN_WIDTH
186185
},
187186
title: {
188187
fontSize: theme.font.medium,

components/CellInput.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class CellInput extends React.Component {
4343
}
4444
}
4545

46+
focus() {
47+
this._textInput.focus();
48+
}
49+
4650
renderTextInput() {
4751
const textInputStyle = this.props.multiline &&
4852
{

components/CellSheet.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class CellSheet extends React.Component {
3838
onClose={this.props.onClose}
3939
onOpen={this.props.onOpen}
4040
mode={this.props.mode}
41+
cancelText={this.props.cancelText || 'Cancel'}
4142
>
4243
{this.props.children /* children should go here, not to the Cell */}
4344
</ActionSheet>

components/DatePicker.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ class DatePicker extends React.Component {
4949

5050
render() {
5151
return (
52-
<ActionSheet ref={component => this._actionSheet = component} >
52+
<ActionSheet
53+
ref={component => this._actionSheet = component}
54+
cancelText="Done"
55+
>
5356
{
5457
Platform.OS === 'ios' &&
5558
<DatePickerIOS
@@ -58,7 +61,6 @@ class DatePicker extends React.Component {
5861
onDateChange={this.handleOnDateChange}
5962
/>
6063
}
61-
<ActionItem title="Done" destructive />
6264
</ActionSheet>
6365
);
6466
}

components/SelectList.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,12 @@ class SelectList extends React.Component {
219219

220220
renderListView() {
221221
if (!this.props.data) {
222-
const title = <Text style={styles.placeholder}>{this.props.placeholder ? this.props.placeholder : DEFAULT_PLACEHOLDER }</Text>;
223222
return (
224223
<View>
225224
{this.renderHeader()}
226-
<Cell title={title} />
225+
<Cell>
226+
<Text style={styles.placeholder}>{this.props.placeholder ? this.props.placeholder : DEFAULT_PLACEHOLDER }</Text>
227+
</Cell>
227228
<View style={styles.separator} />
228229
{this.props.renderFooter && this.props.renderFooter()}
229230
</View>
@@ -254,6 +255,7 @@ class SelectList extends React.Component {
254255
onClose={this.props.onClose}
255256
onOpen={this.props.onOpen}
256257
mode="list"
258+
cancelText={null}
257259
>
258260
<BlurView blurType="xlight" >
259261
{this.renderListView()}

0 commit comments

Comments
 (0)