Skip to content

Commit

Permalink
feat: iOS use custom action sheet (#281)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This implementation is backwards compatible, but just to be safe I'm marking this as breaking so that it bumps the major version.
  • Loading branch information
bradbyte authored Oct 26, 2022
1 parent 86fabab commit 372dc80
Show file tree
Hide file tree
Showing 5 changed files with 429 additions and 374 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ React Native Action Sheet is a cross-platform React Native component that uses t
| -------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------- |
| <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/ios.gif" width="200" height="400"/> | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/android.gif" width="200" height="400"/> | <img src="https://raw.githubusercontent.com/expo/react-native-action-sheet/master/gif/web.gif" width="400" height="400"/> |

## <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAgVBMVEX///8AAACHh4fh4eGZmZl4eHj8/PwEBAT5+fkNDQ0JCQkTExPz8/Pv7+/n5+cQEBAlJSXKyspFRUUZGRnR0dEwMDArKyuAgIAgICA2NjZtbW1eXl5TU1PX19e5ubm/v7+jo6Ovr69ycnKQkJBISEhSUlI7OzuoqKiysrJcXFxlZWVHm5C5AAALb0lEQVR4nO2daXvqKhSFkzpHTR2rbY9Tbav1///ASyCJCWxgMyXtfVxf7j02RN7IsNhAiKKHHnrooYf+P0pvz/86bWfCXcPzKI7jpDdpOyOOus5ipuWx7ay4aPeZMbwcv7P/vM7bzo6tph8Dkv/ncz+KjssM5T1tO0s26nfHJO+D25T+a9JLyL9GT8OWc2Wuwzr7DRar8oPOV/bB7NpinizU+clyvb3UPty/ZB9+7lrKk4WGm6wcJRu+HPXPz1lp+5i2kitzXbbZk/+BOsHpLav/426/8UyZa8Xa2oPyz2vZn7VKV4f9YRW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BzMuo2Ya0EdFmcG4v3ESa3QZyCagLRzYvgT/W5t+4IHMT8ywJNQsRY0iMVbbP0JEWvBgvg06zbSn6WLAnE5MsCTtEd8I0ACmHUbaY741oIEMus2Up64qQOxfjNiEMljLRqQmdu7aPxLGmtRggQ36zaSxFpUIB7ejBhEsGuRghgf8dygoBkiCUiDZt1G+UvKq64FBLE94rlBCa+Nh0AcjnhuUJxrEUEcj3huTnXXwoMs3Y94bk5V11IHsTrfq03dXUsNxO4QkHZVuJYKyC8w6zbKXUu5YMDtoJxWlVYOTfpFZt1G5aoaL4eGt6pjtszJ8cWRv0OTRfLzC836Qw899NBDvvUfXky6QPNuFGIAAAAASUVORK5CYII=" height="20" width="20" /> [Check out the example snack here!](https://snack.expo.dev/@expo-action-sheet/example)
## [Check out the example snack here!](https://snack.expo.dev/@expo-action-sheet/example)

## Installation

Expand Down Expand Up @@ -122,7 +122,7 @@ This library can also be used in the browser with Expo for web.
| `anchor` | number | iPad only option that allows for docking the action sheet to a node. See [ShowActionSheetButton.tsx](/example/ShowActionSheetButton.tsx) for an example on how to implement this. |
| `userInterfaceStyle` | string | The interface style used for the action sheet, can be set to `light` or `dark`, otherwise the default system style will be used. |

### Android/Web-Only Props
### Custom Action Sheet Only (Android/Web) Props

The below props allow modification of the Android ActionSheet. They have no effect on the look on iOS as the native iOS Action Sheet does not have options for modifying these options.

Expand All @@ -144,9 +144,21 @@ The below props allow modification of the Android ActionSheet. They have no effe

The following props can be set directly on the `ActionSheetProvider`

| Name | Type | Description |
| ----------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `useNativeDriver` | boolean | Windows only option that provides the option to disable the [native animation](https://reactnative.dev/docs/animated#using-the-native-driver) driver for React Native Windows projects targeting _Windows 10 Version-1809 ; Build-10.0.17763.0_ and earlier. `useNativeDriver` is [supported in Version-1903 and later](https://microsoft.github.io/react-native-windows/docs/win10-compat) so if your project is targeting that, you don't need to set this prop. |
| Name | Type | Description |
| ---------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `useCustomActionSheet` | boolean | iOS only prop that uses the custom pure JS action sheet (Android/Web version) instead of the native ActionSheetIOS component. Defaults to `false`. |
| `useNativeDriver` | boolean | Windows only option that provides the option to disable the [native animation](https://reactnative.dev/docs/animated#using-the-native-driver) driver for React Native Windows projects targeting _Windows 10 Version-1809 ; Build-10.0.17763.0_ and earlier. `useNativeDriver` is [supported in Version-1903 and later](https://microsoft.github.io/react-native-windows/docs/win10-compat) so if your project is targeting that, you don't need to set this prop. |

```jsx
// example of using useCustomActionSheet on iOS
export default function AppContainer() {
return (
<ActionSheetProvider useCustomActionSheet={true}>
<App />
</ActionSheetProvider>
);
}
```

## Callback

Expand Down
58 changes: 48 additions & 10 deletions example/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
connectActionSheet,
ActionSheetProps,
} from '@expo/react-native-action-sheet';
import { Entypo } from '@expo/vector-icons';
import * as React from 'react';
import { useState } from 'react';
import {
Modal,
StyleSheet,
Expand All @@ -13,11 +15,15 @@ import {
SafeAreaView,
TouchableOpacity,
Share,
Platform,
} from 'react-native';

import ShowActionSheetButton from './ShowActionSheetButton';

type Props = ActionSheetProps;
type Props = ActionSheetProps & {
useCustomActionSheet: boolean;
setUseCustomActionSheet: (next: boolean) => void;
};

interface State {
selectedIndex?: number | null;
Expand Down Expand Up @@ -77,6 +83,35 @@ class App extends React.Component<Props, State> {
style={{
alignItems: 'center',
}}>
<View
style={{
alignItems: 'center',
display: Platform.OS === 'ios' ? 'flex' : 'none',
}}>
{this._renderSectionHeader('Use Custom Action Sheet')}
<Text style={{ marginBottom: 10 }}>
On iOS the default action sheet will be the native UI. However, you can optionally
enable the custom JS action sheet by setting the useCustomActionSheet prop on the
provider.
</Text>
<Entypo.Button
backgroundColor={this.props.useCustomActionSheet ? '#3e3e3e' : 'white'}
name={this.props.useCustomActionSheet ? 'check' : 'circle'}
color={this.props.useCustomActionSheet ? '#fff' : '#3e3e3e'}
style={{
borderColor: '#3e3e3e',
borderWidth: 2,
}}
onPress={() => this.props.setUseCustomActionSheet(!this.props.useCustomActionSheet)}>
<Text
style={{
fontSize: 15,
color: this.props.useCustomActionSheet ? '#fff' : '#3e3e3e',
}}>
Use Custom Action Sheet
</Text>
</Entypo.Button>
</View>
{this._renderSectionHeader('Universal Options')}
<ShowActionSheetButton
title="Options Only"
Expand Down Expand Up @@ -217,16 +252,19 @@ class App extends React.Component<Props, State> {
}
}

const ConnectedApp = connectActionSheet<object>(App);
const ConnectedApp = connectActionSheet<any>(App);

export default class AppContainer extends React.Component {
render() {
return (
<ActionSheetProvider>
<ConnectedApp />
</ActionSheetProvider>
);
}
export default function WrappedApp() {
const [useCustomActionSheet, setUseCustomActionSheet] = useState(false);

return (
<ActionSheetProvider useCustomActionSheet={useCustomActionSheet}>
<ConnectedApp
useCustomActionSheet={useCustomActionSheet}
setUseCustomActionSheet={setUseCustomActionSheet}
/>
</ActionSheetProvider>
);
}

const styles = StyleSheet.create({
Expand Down
Loading

0 comments on commit 372dc80

Please sign in to comment.