在反应式原生中,警报中的组件

问题描述 投票:0回答:1

大家好,我需要在警报中加入一个组件(开关)。

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 },
  );
}

上面的代码是错误的,只是想让你知道我应该怎么做。有一种方法可以用默认的组件alert,或者我应该使用一些librarycustom组件?

react-native alert
1个回答
1
投票

这在默认的 react-native 中是不可能的。Alert. 你可以使用这个 图书馆 并使用 Dialog.Switch 或者我建议你使用 模态 以高度定制您的警报。

© www.soinside.com 2019 - 2024. All rights reserved.