Динамическая ссылка firebase не работает в приложении с 2 навигатором - PullRequest
0 голосов
/ 05 июля 2019

Я новичок в реакции.У меня проблема с Dynamic Link Firebase.

Если я установлю initRouterName в BottomTabNavigatgor равным Author, то я вызову динамическую ссылку на BookDetailScreen, она перейдет к правильному BookDetailScreen.

Ноесли я установлю initRouterName в BottomTabNavigator равным Product, то я буду называть динамическую ссылку BookDetailScreen, она перейдет к ProductScreen.

Есть ли способ решить эту проблему?Вот мой код:

Router.js

const ProductNavigator = createStackNavigator({
    Product: {
        screen: ProductScreen
    },
    ProductDetail: {
        screen: ProductDetailScreen,
    }
}, {
    initialRouteName: 'Product'
});

const AuthorNavigator = createStackNavigator({
    Author: {
        screen: AuthorScreen
    },
    Book: {
        screen: BookScreen
    },
    BookDetail: {
        screen: BookDetailScreen
    }
}, {
    initialRouteName: 'Author'
});

const AppNavigator = createBottomTabNavigator({
    Author: {
        screen: AuthorNavigator
    },
    Product: {
        screen: ProductNavigator
    }
}, {
    initialRouteName: 'Product'
});


const AppContainer = createAppContainer(AppNavigator);

const MainApp = () => <AppContainer />

export default MainApp;

AuthorScreen.js

export default class AuthorScreen extends Component {
    static navigationOptions = {
        title: 'Author'
    };

    componentDidMount() {
        firebase.links().getInitialLink()
        .then(url => {
            if (url) {
                this.navigate(url);
            } else {
                console.log('URL null');
            }
        })
        .catch(error => console.error(error));
    }

    navigate = url => {
        const {navigate} = this.props.navigation;
        const route = url.replace(/.*?:\/\//g, '');
        const routeName = route.split('/')[0];
        const authorId = route.split('/')[1];
        const bookId = route.split('/')[2];

        if (routeName === 'BookDetail') {
            for (author of authors) {
                if (author.id === parseInt(authorId)) {
                    for (book of author.books) {
                        if (book.id === bookId.toString()) {
                            navigate(routeName, {
                                content: book.content
                            });
                        }
                    }
                }
            }
        }
    }

    render() {
        return (
            <View style={{flex: 1, justifyContent: 'center', alignContent: 'center'}}>
                <FlatList
                    data={authors}
                    renderItem={({item}) => {
                        return (
                            <TouchableOpacity
                                onPress={() => this.props.navigation.navigate('Book', {
                                    books: item.books,
                                })}
                            >
                                <Text>{item.name}</Text>
                            </TouchableOpacity>
                        );
                    }}
                    keyExtractor={item => item.id.toString()}
                />
            </View>
        )
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...