Реагировать на собственное предупреждение показывает ошибку, когда onPress на кнопку ОК - PullRequest
0 голосов
/ 22 мая 2018

Я пытаюсь показать предупреждение при использовании коммутатора (atm только на Ios), но он показывает ошибку:

JSON value '({text = OK;})' of type NSMutableArray cannot be converted to NSString

Это пример кода, который я использую:

import React, { Component } from 'react';
import { StyleSheet,Text,View,Button,TouchableOpacity,TextInput,AsyncStorage,ScrollView, Alert,Switch } from 'react-native';
import RNRestart from 'react-native-restart';

export default class ProfileScreen extends Component {    
    constructor(props) {
        super(props);
        this.state = {
            colorPattern: false
        }
    }

    saveThemeColour(color) {
        if(color) {
            AsyncStorage.setItem('themeColour', 'default');
            this.setState({colorPattern: true});
            Alert.alert(
                I18n.t('restart theme change'),
                [
                    {text: 'OK', onPress: () => RNRestart.Restart()}
                ],
                { cancelable: false }
            )
        }else{
            AsyncStorage.setItem('themeColour', 'white');
            this.setState({colorPattern: false});
        }
    }
    <Switch value={this.state.colorPattern} onValueChange={ (value) => this.saveThemeColour(value)}/>
}

Хорошо работает, когда я просто оставляю заголовок предупреждения.

1 Ответ

0 голосов
/ 22 мая 2018

Отсутствует сообщение :

Alert.alert(
  I18n.t('restart theme change'),
  <here-comes-the-message-as-string>,
  [
    {text: 'OK', onPress: () => RNRestart.Restart()}
  ],
  { cancelable: false }
)
...