import React, { useState } from 'react';
import {
SafeAreaView,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import App from './origin/App';
import AppTest from './rnt/testCase/clipPathTest/index';
type Page = 'home' | 'app' | 'index';
const NavBar = ({ title, onBack }: { title: string; onBack: () => void }) => (
<View style={styles.navBar}>
<TouchableOpacity style={styles.backButton} onPress={onBack}>
<Text style={styles.backButtonText}>返回</Text>
</TouchableOpacity>
<Text style={styles.navTitle}>{title}</Text>
</View>
);
const Home = () => {
const [page, setPage] = useState<Page>('home');
const goBack = () => setPage('home');
if (page === 'app') {
return (
<SafeAreaView style={styles.page}>
<NavBar title="App.tsx" onBack={goBack} />
<App />
</SafeAreaView>
);
}
if (page === 'index') {
return (
<SafeAreaView style={styles.page}>
<NavBar title="index" onBack={goBack} />
<AppTest />
</SafeAreaView>
);
}
return (
<SafeAreaView style={styles.container}>
<View style={styles.header}>
<Text style={styles.headerTitle}>ClipPathView Demo</Text>
</View>
<View style={styles.buttonGroup}>
<TouchableOpacity
style={styles.button}
activeOpacity={0.7}
onPress={() => setPage('app')}>
<Text style={styles.buttonText}>App.tsx</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
activeOpacity={0.7}
onPress={() => setPage('index')}>
<Text style={styles.buttonText}>index</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FFFFFF',
},
header: {
padding: 20,
alignItems: 'center',
},
headerTitle: {
fontSize: 24,
fontWeight: 'bold',
},
buttonGroup: {
flex: 1,
alignItems: 'center',
paddingTop: 40,
},
button: {
width: '80%',
paddingVertical: 14,
borderRadius: 8,
alignItems: 'center',
backgroundColor: '#2089dc',
marginBottom: 20,
},
buttonText: {
color: '#FFFFFF',
fontSize: 16,
fontWeight: '600',
},
page: {
flex: 1,
backgroundColor: '#FFFFFF',
},
navBar: {
height: 48,
flexDirection: 'row',
alignItems: 'center',
backgroundColor: '#F5F5F5',
borderBottomWidth: StyleSheet.hairlineWidth,
borderBottomColor: '#CCCCCC',
},
backButton: {
paddingHorizontal: 12,
height: '100%',
justifyContent: 'center',
},
backButtonText: {
fontSize: 16,
color: '#2089dc',
},
navTitle: {
fontSize: 17,
fontWeight: '600',
},
});
export default Home;