Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加busscreen 改buscontroller #15

Merged
merged 1 commit into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function MainApp() {
}

export default function App() {
if (!firebase.apps.length) {
/*if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
} else {
firebase.app();
Expand All @@ -150,5 +150,14 @@ export default function App() {
>
{ auth ? <MainApp /> : <AuthScreen />}
</PaperProvider>
);*/
return (
<PaperProvider
settings={{
icon: (props) => <AwesomeIcon {...props} />,
}}
>
<MainApp />
</PaperProvider>
);
}
390 changes: 390 additions & 0 deletions controller/Bus.js

Large diffs are not rendered by default.

103 changes: 102 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@react-navigation/native": "^6.0.6",
"@react-navigation/native-stack": "^6.2.5",
"@react-navigation/stack": "^6.1.1",
"axios": "^0.21.2",
"expo": "^44.0.0",
"expo-constants": "~13.0.0",
"expo-facebook": "~12.1.0",
Expand All @@ -24,6 +25,7 @@
"expo-location": "~14.0.1",
"expo-push-notification-helper": "^0.4.0",
"firebase": "^8.10.0",
"jssha": "^2.3.1",
"native-base": "^3.3.7",
"react": "17.0.1",
"react-dom": "17.0.1",
Expand All @@ -38,7 +40,8 @@
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
"react-native-web": "0.17.1",
"expo-status-bar": "~1.2.0"
"expo-status-bar": "~1.2.0",
"url": "^0.11.0"
},
"devDependencies": {
"@babel/core": "^7.12.9",
Expand Down
10 changes: 0 additions & 10 deletions screens/Map/BusScreen.jsx

This file was deleted.

135 changes: 135 additions & 0 deletions screens/Map/BusScreen/132-1.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
import React, { useState, useEffect } from 'react';
import {
View,
SafeAreaView,
Text,
TouchableOpacity,
RefreshControl,
ScrollView,
} from 'react-native';
import BusController from '../../../controller/Bus';
import Styles from '../Styles';

const Separator = () => <View style={Styles.separator} />;
function Bus132({ navigation }) {
const [item, setItems] = useState([]);

const [start, setStart] = useState(true);

const [direction, setDirection] = useState(1);

const [refreshing, setRefreshing] = useState(false);

const onRefresh = () => {
setRefreshing(true);
BusController.route({ id: 132, dir: 1 }).then((res) => {
setItems(res);
console.log();
setRefreshing(false);
});
};

const onRefresh1 = () => {
setRefreshing(true);
BusController.route({ id: 132, dir: 0 }).then((res) => {
setItems(res);
setRefreshing(false);
});
};

useEffect(() => {
if (start) {
setStart(false);
if (direction === 1)onRefresh();
else onRefresh1();
}
let id;
if (direction === 1)id = setInterval(onRefresh, 10000);
else id = setInterval(onRefresh1, 10000);
return () => {
clearInterval(id);
};
}, [start]);

return (
<SafeAreaView
style={Styles.background}
refreshControl={(<RefreshControl refreshing={refreshing} onRefresh={onRefresh} />)}
>
<View>
<Text style={{
textAlign: 'center', backgroundColor: '#28527A', color: 'white', height: 50, width: '100%', fontSize: 20, textAlignVertical: 'center', lineHeight: 50,
}}
>
132
</Text>
<TouchableOpacity
onPress={() => { navigation.navigate('List132'); }}
style={{
width: '25%',
top: 15,
left: 280,
backgroundColor: '#FFE66F',
position: 'absolute',
right: 0,
}}
>
<Text style={Styles.title}>發車時刻表</Text>
</TouchableOpacity>
</View>

<View>
<View style={{ flexDirection: 'row', height: 50 }}>
<TouchableOpacity
onPress={() => { setStart(true); setDirection(0); }}
style={{ width: '50%', backgroundColor: 'white' }}
>
<Text style={{
textAlign: 'center', fontSize: 20, textAlignVertical: 'center', lineHeight: 50,
}}
>
往中央大學
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => { setStart(true); setDirection(1); }}
style={{ width: '50%', backgroundColor: 'white' }}
>
<Text style={{
textAlign: 'center', fontSize: 20, textAlignVertical: 'center', lineHeight: 50,
}}
>
往中壢公車站
</Text>
</TouchableOpacity>
</View>
</View>
<Text style={{ fontSize: 1 }}>{'\n'}</Text>
<ScrollView>
{ item.map((data) => (
<View>
<View style={{ flexDirection: 'row', height: 50 }}>
<Text style={{
textAlign: 'center', width: '50%', backgroundColor: 'white', fontSize: 20, textAlignVertical: 'center', lineHeight: 50,
}}
>
{data.time}
</Text>
<Text style={{
width: '50%', backgroundColor: 'white', fontSize: 20, textAlignVertical: 'center', lineHeight: 50,
}}
>
{data.state}
</Text>

</View>
<Separator />
</View>

))}
</ScrollView>
</SafeAreaView>
);
}

export default Bus132;
Loading