Skip to content

Commit

Permalink
ImagePicker: Handle maxfiles correctly.
Browse files Browse the repository at this point in the history
Adds an option in composeMenu.js to pass in a maxFiles number.

This is used to make sure the user can only select the correct
number of files when selecting images.
  • Loading branch information
armaanahluwalia committed Oct 11, 2018
1 parent 4ffadc4 commit 80dc06d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/compose/ComposeBox.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ class ComposeBox extends PureComponent<Props, State> {
onImageSelect={this.handleImageSelect}
disableCamera={draftImages && Object.keys(draftImages).length >= 4}
disableUpload={draftImages && Object.keys(draftImages).length >= 4}
maxFiles={4 - Object.keys(draftImages).length}
/>
</View>
<View style={styles.composeText}>
Expand Down
5 changes: 3 additions & 2 deletions src/compose/ComposeMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type Props = {
onImageSelect: Object => void,
disableUpload?: boolean,
disableCamera?: boolean,
maxFiles?: number,
};

/*
Expand Down Expand Up @@ -68,7 +69,7 @@ class ComposeMenu extends PureComponent<Props> {
};

handleImageRequest = async (requestType: 'openPicker' | 'openCamera') => {
const { dispatch, narrow, onImageSelect } = this.props;
const { dispatch, narrow, onImageSelect, maxFiles } = this.props;
const defaults = {
mediaType: 'photo',
compressImageMaxWidth: 2000,
Expand All @@ -85,7 +86,7 @@ class ComposeMenu extends PureComponent<Props> {
requestObj = {
...defaults,
multiple: true,
maxFiles: 4,
maxFiles,
};
}
let images = await ImagePicker[requestType](requestObj);
Expand Down

0 comments on commit 80dc06d

Please sign in to comment.