我用 react-navigation 中的 createMaterialTopTabNavigator 创建了两个选项卡。我喜欢为两个选项卡设置一个背景图像。
当前的行为是,当我从 tab1 滑动到 tab2 时,图像也会过渡,但我喜欢在从 tab1 过渡到 tab2 时使背景图像保持静态,并且在滑动时只有选项卡的内容才能过渡。我尝试将 TabNavigator 包装在 ImageBackground 组件中,但这没有用。
我用 react-navigation 中的 createMaterialTopTabNavigator 创建了两个选项卡。我喜欢为两个选项卡设置一个背景图像。
当前的行为是,当我从 tab1 滑动到 tab2 时,图像也会过渡,但我喜欢在从 tab1 过渡到 tab2 时使背景图像保持静态,并且在滑动时只有选项卡的内容才能过渡。我尝试将 TabNavigator 包装在 ImageBackground 组件中,但这没有用。
我认为您可以使用以下解决方案之一:
<View>
导航器上方。您可以在此处的 React Navigation 文档中找到有关样式卡的详细信息。shared
道具,你就完成了:)这是演示:https ://snack.expo.io/@nomi9995/e05080
使用react-native-tab-view并将 TabView 包装在其中的更好方法ImageBackground
yarn add react-native-tab-view
import React, { Component } from "react";
import {
Text,
StyleSheet,
View,
SafeAreaView,
ImageBackground,
Dimensions,
} from "react-native";
import { TabView, SceneMap } from "react-native-tab-view";
const width = Dimensions.get("window").width;
function FirstRoute() {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>FirstRoute!</Text>
</View>
);
}
function SecondRoute() {
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>SecondRoute!</Text>
</View>
);
}
export default class App extends Component {
state = {
index: 0,
routes: [
{ key: "first", title: "First" },
{ key: "second", title: "Second" },
],
};
render() {
const { index, routes } = this.state;
const renderScene = SceneMap({
first: FirstRoute,
second: SecondRoute,
});
return (
<SafeAreaView style={{ flex: 1 }}>
<ImageBackground
style={{ flex: 1, width: width }}
source={{
uri:
"https://firebasestorage.googleapis.com/v0/b/ielts-preps.appspot.com/o/1592920135765?alt=media&token=ec911583-06f9-4315-b66c-cf47de120e85",
}}
>
<TabView
navigationState={{ index, routes }}
renderScene={renderScene}
onIndexChange={(i) => this.setState({ index: i })}
tabBarPosition="bottom"
/>
</ImageBackground>
</SafeAreaView>
);
}
}
const styles = StyleSheet.create({});