2015-03-13 22:30:31 +00:00
|
|
|
/**
|
2018-09-11 22:27:47 +00:00
|
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-07-12 12:51:57 +00:00
|
|
|
*
|
2018-05-11 20:32:37 +00:00
|
|
|
* @format
|
2015-03-23 17:06:16 +00:00
|
|
|
* @flow
|
|
|
|
*/
|
2018-05-11 20:32:37 +00:00
|
|
|
|
2015-03-13 22:30:31 +00:00
|
|
|
'use strict';
|
|
|
|
|
2016-04-09 03:36:40 +00:00
|
|
|
var React = require('react');
|
|
|
|
var ReactNative = require('react-native');
|
2018-05-11 20:32:37 +00:00
|
|
|
var {ActionSheetIOS, StyleSheet, takeSnapshot, Text, View} = ReactNative;
|
|
|
|
|
|
|
|
var BUTTONS = ['Option 0', 'Option 1', 'Option 2', 'Delete', 'Cancel'];
|
2015-03-13 22:30:31 +00:00
|
|
|
var DESTRUCTIVE_INDEX = 3;
|
|
|
|
var CANCEL_INDEX = 4;
|
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ActionSheetExample extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
clicked: 'none',
|
|
|
|
};
|
2015-03-13 22:30:31 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text onPress={this.showActionSheet} style={style.button}>
|
|
|
|
Click to show the ActionSheet
|
|
|
|
</Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>Clicked button: {this.state.clicked}</Text>
|
2015-03-13 22:30:31 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
showActionSheet = () => {
|
2018-05-11 20:32:37 +00:00
|
|
|
ActionSheetIOS.showActionSheetWithOptions(
|
|
|
|
{
|
|
|
|
options: BUTTONS,
|
|
|
|
cancelButtonIndex: CANCEL_INDEX,
|
|
|
|
destructiveButtonIndex: DESTRUCTIVE_INDEX,
|
|
|
|
},
|
|
|
|
buttonIndex => {
|
|
|
|
this.setState({clicked: BUTTONS[buttonIndex]});
|
|
|
|
},
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ActionSheetTintExample extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
|
|
|
clicked: 'none',
|
|
|
|
};
|
2015-12-09 13:08:36 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text onPress={this.showActionSheet} style={style.button}>
|
|
|
|
Click to show the ActionSheet
|
|
|
|
</Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>Clicked button: {this.state.clicked}</Text>
|
2015-12-09 13:08:36 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-12-09 13:08:36 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
showActionSheet = () => {
|
2018-05-11 20:32:37 +00:00
|
|
|
ActionSheetIOS.showActionSheetWithOptions(
|
|
|
|
{
|
|
|
|
options: BUTTONS,
|
|
|
|
cancelButtonIndex: CANCEL_INDEX,
|
|
|
|
destructiveButtonIndex: DESTRUCTIVE_INDEX,
|
|
|
|
tintColor: 'green',
|
|
|
|
},
|
|
|
|
buttonIndex => {
|
|
|
|
this.setState({clicked: BUTTONS[buttonIndex]});
|
|
|
|
},
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-12-09 13:08:36 +00:00
|
|
|
|
2018-05-11 20:32:37 +00:00
|
|
|
class ShareActionSheetExample extends React.Component<
|
|
|
|
$FlowFixMeProps,
|
|
|
|
$FlowFixMeState,
|
|
|
|
> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
2018-05-11 20:32:37 +00:00
|
|
|
text: '',
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2015-03-13 22:30:31 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text onPress={this.showShareActionSheet} style={style.button}>
|
|
|
|
Click to show the Share ActionSheet
|
|
|
|
</Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>{this.state.text}</Text>
|
2015-03-13 22:30:31 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
showShareActionSheet = () => {
|
2018-05-11 20:32:37 +00:00
|
|
|
ActionSheetIOS.showShareActionSheetWithOptions(
|
|
|
|
{
|
|
|
|
url: this.props.url,
|
|
|
|
message: 'message to go with the shared url',
|
|
|
|
subject: 'a subject to go in the email heading',
|
|
|
|
excludedActivityTypes: ['com.apple.UIKit.activity.PostToTwitter'],
|
|
|
|
},
|
|
|
|
error => alert(error),
|
|
|
|
(completed, method) => {
|
|
|
|
var text;
|
|
|
|
if (completed) {
|
|
|
|
text = `Shared via ${method}`;
|
|
|
|
} else {
|
|
|
|
text = "You didn't share";
|
|
|
|
}
|
|
|
|
this.setState({text});
|
|
|
|
},
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2015-03-13 22:30:31 +00:00
|
|
|
|
2017-08-18 01:36:54 +00:00
|
|
|
class ShareScreenshotExample extends React.Component<{}, $FlowFixMeState> {
|
2016-07-26 08:00:02 +00:00
|
|
|
state = {
|
2018-05-11 20:32:37 +00:00
|
|
|
text: '',
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
2016-02-23 10:26:11 +00:00
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Text onPress={this.showShareActionSheet} style={style.button}>
|
|
|
|
Click to show the Share ActionSheet
|
|
|
|
</Text>
|
2018-05-11 20:32:37 +00:00
|
|
|
<Text>{this.state.text}</Text>
|
2016-02-23 10:26:11 +00:00
|
|
|
</View>
|
|
|
|
);
|
2016-07-26 08:00:02 +00:00
|
|
|
}
|
2016-02-23 10:26:11 +00:00
|
|
|
|
2016-07-26 08:00:02 +00:00
|
|
|
showShareActionSheet = () => {
|
2016-02-23 10:26:11 +00:00
|
|
|
// Take the snapshot (returns a temp file uri)
|
2018-05-11 20:32:37 +00:00
|
|
|
takeSnapshot('window')
|
|
|
|
.then(uri => {
|
|
|
|
// Share image data
|
|
|
|
ActionSheetIOS.showShareActionSheetWithOptions(
|
|
|
|
{
|
|
|
|
url: uri,
|
|
|
|
excludedActivityTypes: ['com.apple.UIKit.activity.PostToTwitter'],
|
|
|
|
},
|
|
|
|
error => alert(error),
|
|
|
|
(completed, method) => {
|
|
|
|
var text;
|
|
|
|
if (completed) {
|
|
|
|
text = `Shared via ${method}`;
|
|
|
|
} else {
|
|
|
|
text = "You didn't share";
|
|
|
|
}
|
|
|
|
this.setState({text});
|
|
|
|
},
|
|
|
|
);
|
|
|
|
})
|
|
|
|
.catch(error => alert(error));
|
2016-07-26 08:00:02 +00:00
|
|
|
};
|
|
|
|
}
|
2016-02-23 10:26:11 +00:00
|
|
|
|
2015-03-13 22:30:31 +00:00
|
|
|
var style = StyleSheet.create({
|
|
|
|
button: {
|
|
|
|
marginBottom: 10,
|
2015-03-26 01:19:28 +00:00
|
|
|
fontWeight: '500',
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2015-03-13 22:30:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
exports.title = 'ActionSheetIOS';
|
2018-05-11 20:32:37 +00:00
|
|
|
exports.description = "Interface to show iOS' action sheets";
|
2015-03-13 22:30:31 +00:00
|
|
|
exports.examples = [
|
|
|
|
{
|
|
|
|
title: 'Show Action Sheet',
|
2018-05-11 20:32:37 +00:00
|
|
|
render(): React.Element<any> {
|
|
|
|
return <ActionSheetExample />;
|
|
|
|
},
|
2015-03-13 22:30:31 +00:00
|
|
|
},
|
2015-12-09 13:08:36 +00:00
|
|
|
{
|
|
|
|
title: 'Show Action Sheet with tinted buttons',
|
2018-05-11 20:32:37 +00:00
|
|
|
render(): React.Element<any> {
|
|
|
|
return <ActionSheetTintExample />;
|
|
|
|
},
|
2015-12-09 13:08:36 +00:00
|
|
|
},
|
2015-03-13 22:30:31 +00:00
|
|
|
{
|
|
|
|
title: 'Show Share Action Sheet',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
2016-02-22 13:33:31 +00:00
|
|
|
return <ShareActionSheetExample url="https://code.facebook.com" />;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-02-22 13:33:31 +00:00
|
|
|
},
|
2016-02-23 10:26:11 +00:00
|
|
|
{
|
2016-02-22 13:33:31 +00:00
|
|
|
title: 'Share Local Image',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
2016-02-22 13:33:31 +00:00
|
|
|
return <ShareActionSheetExample url="bunny.png" />;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
2016-02-23 10:26:11 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
title: 'Share Screenshot',
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
2016-02-23 10:26:11 +00:00
|
|
|
return <ShareScreenshotExample />;
|
2018-05-11 20:32:37 +00:00
|
|
|
},
|
|
|
|
},
|
2015-03-13 22:30:31 +00:00
|
|
|
];
|