Sharing a post

Constellational (the app I’m building to give your notes a home online) lets you share posts via the usual suspects – email, message, Twitter, Facebook, etc. I’m doing this using React Native’s ActionSheetIOS.

When a post is tapped a bunch of options show up (Share, Edit, Delete or Cancel), and if Share has been tapped (buttonIndex is zero) the Share sheet is displayed.

This is the code that we’re interested in:

showOptions() {
ActionSheetIOS.showActionSheetWithOptions({
options: ['Share', 'Edit', 'Delete', 'Cancel'],
destructiveButtonIndex: 2,
cancelButtonIndex: 3
}, (buttonIndex) => {
var url = URL + '/' + SettingStore.getUsername() + '/' + this.props.post.id;
if (this.props.post.isDraft || this.props.post.hasUnpublishedEdits) {
var options = {message: this.props.post.data};
} else {
var options = {url: url};
}
if (buttonIndex === 0) {
ActionSheetIOS.showShareActionSheetWithOptions(options, this.shareFailure, this.shareSuccess);
} else if (buttonIndex === 1) {
this.props.nav.push({id: 'edit', post: this.props.post});
} else if (buttonIndex === 2) {
if (this.props.post.isDraft) {
DraftActions.del(this.props.post);
} else {
PostActions.del(this.props.post);
}
}
});
}

Note that if the post is being edited or is still a draft the post contents are shared (for example, if you chose email the body of the mail will be the text of the post). A link is shared if you’ve published the post. Still to come: opening these links in the app instead of the browser. Sounds interesting? Sign up here!