Customize Action Sheet Message (Expo)

568 Views Asked by At

I'm using @expo/react-native-action-sheet, and i want to show a button in the props message.

e.g

import { useActionSheet } from "@expo/react-native-action-sheet"
const { showActionSheetWithOptions } = useActionSheet()

const onPress = () => {

    // Here
    **const message = '<TouchableOpacity><Text>fsdf</Text></TouchableOpacity>'**

    showActionSheetWithOptions(
        {
            message
        },
        (buttonIndex) => {

        }
    )
}

But it is not showing the button as i want

enter image description here

My purpose is to add a date picker in the action sheet.

Expecting answer:

enter image description here

1

There are 1 best solutions below

1
On

In this case, you can use another library https://gorhom.github.io/react-native-bottom-sheet/ because Action Sheet is about the list of actions.

You can place any content you need for react-native-bottom-sheet and it also supports Expo

import React, { useCallback, useMemo, useRef } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import BottomSheet from '@gorhom/bottom-sheet';

const App = () => {
  // ref
  const bottomSheetRef = useRef<BottomSheet>(null);

  // variables
  const snapPoints = useMemo(() => ['25%', '50%'], []);

  // callbacks
  const handleSheetChanges = useCallback((index: number) => {
    console.log('handleSheetChanges', index);
  }, []);

  // renders
  return (
    <View style={styles.container}>
      <BottomSheet
        ref={bottomSheetRef}
        index={1}
        snapPoints={snapPoints}
        onChange={handleSheetChanges}
      >
        <View style={styles.contentContainer}>
          <Text>Awesome </Text>
        </View>
      </BottomSheet>
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    flex: 1,
    padding: 24,
    backgroundColor: 'grey',
  },
  contentContainer: {
    flex: 1,
    alignItems: 'center',
  },
});

export default App;