React native react native中的组件内部警报

React native react native中的组件内部警报,react-native,alert,React Native,Alert,大家好,我需要在警报中放置一个组件开关 export const secretAlert = (environment: object) => { Alert.alert( 'Alert Title', 'My Alert Msg', [ { text: `Environment: ${Config.ENV}`, }, { text: 'Cancel', onPress: ()

大家好,我需要在警报中放置一个组件开关

export const secretAlert = (environment: object) => {
  Alert.alert(
    'Alert Title',
    'My Alert Msg',
    [
      {
        text: `Environment: ${Config.ENV}`,
      },
      {
        text: 'Cancel',
        onPress: () => console.log('Cancel Pressed'),
        style: 'cancel',
      },
      { text: 'OK', onPress: () => console.log('OK Pressed') },
    ],
    { cancelable: false },
  );
    return (
          <Text>test</Text>,
    )
}
第二次尝试

export const secretAlert = (environment: object) => {
  Alert.alert(
    'Alert Title',
    'My Alert Msg',
    [
      {
        text: `Environment: ${Config.ENV}`,
      },
      {
        text: 'Cancel',
        onPress: () => console.log('Cancel Pressed'),
        style: 'cancel',
        switch: <ComponentHere>. 
      },
      { text: 'OK', onPress: () => console.log('OK Pressed') },
    ],
    { cancelable: false },
  );
}
上面的代码是错误的,只是为了让你知道我要做什么。
有一种方法可以使用默认组件警报,还是应该使用一些库/自定义组件

这在默认的react native Alert中是不可能的。您可以使用此选项并使用Dialog.Switch或我建议您使用高度自定义警报。

感谢您的回答:我使用的是自定义模式