Skip to content

Commit

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

This is used to make sure the user can only select the correct
number of files subject to our max of 4.
  • Loading branch information
armaanahluwalia committed Sep 10, 2018
1 parent 261b877 commit 7741d04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/compose/ComposeBox.ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,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
4 changes: 3 additions & 1 deletion 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,
};

class ComposeMenu extends Component<Props> {
Expand All @@ -45,13 +46,14 @@ class ComposeMenu extends Component<Props> {

handleImageUpload = () => {
const { handleImagePickerResponse } = this;
const { maxFiles } = this.props;
ImagePicker.openPicker({
mediaType: 'photo',
multiple: true,
compressImageMaxWidth: 1600,
compressImageMaxHeight: 1600,
compressImageQuality: 0.7,
maxFiles: 4,
maxFiles,
})
.then(images => {
handleImagePickerResponse({
Expand Down

0 comments on commit 7741d04

Please sign in to comment.