Skip to content
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
2 changes: 1 addition & 1 deletion app.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
favicon: './assets/images/logoIcon.png',
},
extra: {
BASE_URL: 'http://192.168.0.115:8081', // ๋ณธ์ธ pc IPv4 ์ฃผ์†Œ๋กœ ์ˆ˜์ •ํ•˜์„ธ์šฉ
BASE_URL: 'http://192.168.0.181:8081', // ๋ณธ์ธ pc IPv4 ์ฃผ์†Œ๋กœ ์ˆ˜์ •ํ•˜์„ธ์šฉ
},
},
};
36 changes: 36 additions & 0 deletions components/cards/Dot.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React, { useEffect, useRef } from 'react';
import { Animated, StyleSheet } from 'react-native';
import { styles } from './styles/Dot.styles';
import { colors } from '../../constants/colors';

// dot์˜ ๊ธฐ๋ณธ ๋„ˆ๋น„์™€ ํ™œ์„ฑํ™”(์„ ํƒ) ์ƒํƒœ์ผ ๋•Œ์˜ ๋„ˆ๋น„
const DOT_WIDTH = 10;
const DOT_ACTIVE_WIDTH = 16;

const Dot = ({ active }) => {
// dot width๋ฅผ ์œ„ํ•œ Animated.Value ๋ฐฐ์—ด
const animatedWidth = useRef(new Animated.Value(active ? DOT_ACTIVE_WIDTH : DOT_WIDTH)).current;

// pageIndex๊ฐ€ ๋ฐ”๋€” ๋•Œ dot width ์• ๋‹ˆ๋ฉ”์ด์…˜
useEffect(() => {
Animated.timing(animatedWidth, {
toValue: active ? DOT_ACTIVE_WIDTH : DOT_WIDTH,
duration: 300,
useNativeDriver: false,
}).start();
}, [active, animatedWidth]);

return (
<Animated.View
style={[
styles.dot,
{
width: animatedWidth,
backgroundColor: active ? colors.primary : colors.lightGreen,
},
]}
/>
);
};

export default Dot;
47 changes: 47 additions & 0 deletions components/cards/QrCard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, { useState } from 'react';
import { View, Text, Image } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import QRCode from 'react-native-qrcode-svg';

import NormalButton from '../../components/buttons/NormalButton';
import { styles } from './styles/QrCard.styles';
import { colors } from '../../constants/colors';
import { hospitalName } from '../../mocks/hospitalData';

// hasAccessAuthority: ์ถœ์ž… ๊ถŒํ•œ ์—ฌ๋ถ€, userVC : VC์— ๋‹ด์„ ์‚ฌ์šฉ์ž ์ •๋ณด, qrData : QR์— ๋‹ด์„ JSON ๋ฌธ์ž์—ด
const QrCard = ({ hasAccessAuthority, did, userName, hospitalName }) => {
// ํ•ด๋‹น QR์˜ ์ƒ์„ธ ํŽ˜์ด์ง€๋กœ ์ด๋™ (์•„์ง ๋ฏธ๊ตฌํ˜„)
//const navigation = useNavigation();
// const navigateToAccessListDeatail = () => {
// navigation.navigate('AccessListDetailPage');
// };

// ์ž„์‹œ: QR์— ๋‹ด์„ JSON ๋ฌธ์ž์—ด
const qrData = JSON.stringify({ did, userName, hospitalName });
return (
<View style={styles.shadowWrapper}>
<View style={styles.cardContainer}>
<Image
style={styles.backgroundImage}
source={require('../../assets/images/mainBackground.png')}
resizeMode="contain" // ์ด๋ฏธ์ง€ ๋น„์œจ ์œ ์ง€
/>
{hasAccessAuthority ? (
<>
<Text style={styles.qrTitle}>์ž„์‹œ ์ถœ์ž… QR</Text>
<QRCode value={qrData} size={140} color={colors.black} backgroundColor={colors.white} />
<Text style={styles.userName}>{userName}</Text>
<Text style={styles.hospital}>{hospitalName}</Text>
</>
) : (
<>
<Text style={styles.cardText}>๋“ฑ๋ก๋œ ์ถœ์ž… ๊ถŒํ•œ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</Text>
<Text style={styles.cardSubText}>๋ฐฉ๋ฌธ ์‹ ์ฒญ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ถœ์ž… ๊ถŒํ•œ์„ ์‹ ์ฒญํ•ด์ฃผ์„ธ์š”.</Text>
</>
)}
</View>
</View>
);
};

export default QrCard;
83 changes: 83 additions & 0 deletions components/cards/QrCards.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import React, { useRef, useState } from 'react';
import { FlatList, View, Dimensions, TouchableOpacity } from 'react-native';
import QrCard from './QrCard';
import styles from './styles/QrCards.styles';
import Dot from './Dot';

// ํ™”๋ฉด์˜ ๊ฐ€๋กœ ๊ธธ์ด ๊ฐ€์ ธ์˜ค๊ธฐ
const { width } = Dimensions.get('window');
const CARD_WIDTH = width;
const SIDE_PADDING = (width - CARD_WIDTH) / 2; // ์ขŒ์šฐ ํŒจ๋”ฉ ๊ณ„์‚ฐ
const OVERLAP = 80; // ์นด๋“œ๊ฐ€ ๊ฒน์น˜๋Š” ์ •๋„

const QrCards = ({ userVC, hasAccessAuthority }) => {
const [pageIndex, setPageIndex] = useState(0);
const flatListRef = useRef(null);

// ๊ถŒํ•œ ์—†๊ฑฐ๋‚˜ ์นด๋“œ ๋ฐ์ดํ„ฐ ์—†์œผ๋ฉด ์•ˆ๋‚ด ๋ฉ”์‹œ์ง€ ์นด๋“œ๋งŒ
if (!hasAccessAuthority || !userVC || userVC.length === 0) {
return (
<View style={{ flex: 0.8, width, alignItems: 'center' }}>
<QrCard hasAccessAuthority={false} />
</View>
);
}

// ์Šคํฌ๋กค์ด ๋๋‚ฌ์„ ๋•Œ ํ˜„์žฌ ํŽ˜์ด์ง€ ์ธ๋ฑ์Šค ๊ณ„์‚ฐ
const onMomentumScrollEnd = (event) => {
const offsetX = event.nativeEvent.contentOffset.x;
const newIndex = Math.round(offsetX / (CARD_WIDTH - OVERLAP));
setPageIndex(newIndex);
};

// dot(์ธ๋””์ผ€์ดํ„ฐ) ํด๋ฆญ ์‹œ ํ•ด๋‹น ์นด๋“œ๋กœ ์ด๋™
const handleDotPress = (index) => {
flatListRef.current?.scrollToIndex({ index, animated: true });
};

// ์นด๋“œ ๋ฆฌ์ŠคํŠธ
return (
<View style={{ flex: 0.8 }}>
<FlatList
ref={flatListRef}
data={userVC}
keyExtractor={(item) => item.did}
horizontal //๊ฐ€๋กœ ์Šคํฌ๋กค
showsHorizontalScrollIndicator={false} //ํ•˜๋‹จ ๊ธฐ๋ณธ ์Šคํฌ๋กค๋ฐ” ์ˆจ๊น€
pagingEnabled={false} // snapToInterval์„ ์‚ฌ์šฉํ•˜๋ฏ€๋กœ false
snapToInterval={CARD_WIDTH - OVERLAP} // ์นด๋“œ ๋‹จ์œ„๋กœ ์Šค๋ƒ…
decelerationRate="fast" // ๋น ๋ฅธ ์Šค๋ƒ… ํšจ๊ณผ
contentContainerStyle={{
paddingHorizontal: SIDE_PADDING, // ์–‘์ชฝ์— ํŒจ๋”ฉ ์ถ”๊ฐ€๋กœ ์˜† ์นด๋“œ ์‚ด์ง ๋ณด์ด๊ฒŒ
}}
renderItem={({ item, index }) => (
<View
style={{
width: CARD_WIDTH,
marginLeft: index === 0 ? 0 : -OVERLAP, // ์ฒซ ์นด๋“œ๋Š” ๊ฒน์น˜์ง€ ์•Š๊ฒŒ
alignItems: 'center',
zIndex: pageIndex === index ? 1 : 0, // ์„ ํƒ๋œ ์นด๋“œ๊ฐ€ ์œ„๋กœ ์˜ค๊ฒŒ
}}
>
<QrCard
did={item.did}
userName={item.userName}
hospitalName={item.hospitalName}
hasAccessAuthority={true}
/>
</View>
)}
onMomentumScrollEnd={onMomentumScrollEnd}
/>
<View style={styles.dotContainer}>
{userVC.map((_, i) => (
<TouchableOpacity key={`dot-${i}`} onPress={() => handleDotPress(i)}>
<Dot active={pageIndex === i} />
</TouchableOpacity>
))}
</View>
</View>
);
};

export default QrCards;
10 changes: 10 additions & 0 deletions components/cards/styles/Dot.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { StyleSheet } from 'react-native';
import { colors } from '../../../constants/colors';

export const styles = StyleSheet.create({
dot: {
height: 10,
borderRadius: 16,
marginHorizontal: 4,
},
});
65 changes: 65 additions & 0 deletions components/cards/styles/QrCard.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { StyleSheet } from 'react-native';
import { colors } from '../../../constants/colors';

export const styles = StyleSheet.create({
shadowWrapper: {
// ๊ทธ๋ฆผ์ž ์„ค์ •
shadowColor: 'black',
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.2,
shadowRadius: 5,
elevation: 7, // Android์šฉ
borderRadius: 15,
width: '70%',
height: '80%',
marginVertical: '10%',
},
cardContainer: {
flex: 1, // ๋ถ€๋ชจ(shadowWrapper)์˜ ํฌ๊ธฐ๋ฅผ ๊ฝ‰ ์ฑ„์›Œ ์นด๋“œ์™€ ๊ทธ๋ฆผ์ž ๋ชจ์–‘์„ ์ผ์น˜์‹œํ‚ด
backgroundColor: colors.white,
borderRadius: 15,
padding: '10%',
alignItems: 'center',
justifyContent: 'center',
overflow: 'hidden', // ๋ฐฐ๊ฒฝ ์ด๋ฏธ์ง€๊ฐ€ ์นด๋“œ ์•ˆ์— ์ž˜๋ฆฌ๊ฒŒ
position: 'relative', // ์ž์‹์˜ absolute ํฌ์ง€์…˜ ๊ธฐ์ค€์ 
},
backgroundImage: {
...StyleSheet.absoluteFillObject, // ์ „์ฒด ์นด๋“œ ๋ฎ๊ฒŒ ๋งŒ๋“ฆ
width: '125%',
zIndex: 0, // ๋งจ ๋’ค๋กœ
opacity: 0.5,
},
cardText: {
fontSize: 20,
fontWeight: 600,
color: colors.black,
textAlign: 'center',
marginBottom: '5%',
},
cardSubText: {
fontSize: 16,
fontWeight: 500,
color: colors.darkGray,
textAlign: 'center',
},
qrTitle: {
fontSize: 26,
fontWeight: 700,
color: colors.black,
marginBottom: '10%',
zIndex: 1, // QR๊ณผ ํ…์ŠคํŠธ๋ฅผ ๋ฐฐ๊ฒฝ ์œ„์—
},
userName: {
fontSize: 24,
fontWeight: 600,
color: colors.black,
marginVertical: '8%',
},
hospital: {
fontSize: 16,
fontWeight: 500,
color: colors.darkGray,
marginTop: '2%',
},
});
11 changes: 11 additions & 0 deletions components/cards/styles/QrCards.styles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { StyleSheet } from 'react-native';

const styles = StyleSheet.create({
dotContainer: {
flexDirection: 'row',
justifyContent: 'center',
marginBottom: '5%',
},
});

export default styles;
63 changes: 23 additions & 40 deletions pages/MainPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,35 @@ import NormalButton from '../components/buttons/NormalButton';
import { styles } from './styles/MainPage.styles';
import QRCode from 'react-native-qrcode-svg';
import { colors } from '../constants/colors';
import QrCards from '../components/cards/QrCards';

const MainPage = () => {
// ์ž„์‹œ: ์ƒํƒœ๋ณ€์ˆ˜๋กœ ์ถœ์ž… ๊ถŒํ•œ ์ œ์–ด
const [hasAccessAuthority, setHasAccessAuthority] = useState(true);

// ์ž„์‹œ: VC์— ๋‹ด์„ ์‚ฌ์šฉ์ž ์ •๋ณด
const userVC = {
did: 'did:example:123456789abcdefghi',
userName: '๊น€์งฑ๊ตฌ',
hospital1: '์งฑ๊ตฌ๋ณ‘์›',
hospital2: 'ํฐ๋‘ฅ์ด๋ณ‘์›',
hospital3: '์˜ค์ˆ˜๋ณ‘์›',
issuedAt: Date.now(),
};
const userVC = [
{
did: 'did:example:123456789abcdefghi',
userName: '๊น€์งฑ๊ตฌ',
hospitalName: '์งฑ๊ตฌ๋ณ‘์›',
issuedAt: Date.now(),
},
{
did: 'did:example:123456789abcdefdhi',
userName: '๊น€์งฑ๊ตฌ',
hospitalName: 'ํฐ๋‘ฅ์ด๋ณ‘์›',
issuedAt: Date.now(),
},
{
did: 'did:example:123456789abcdeffhi',
userName: '๊น€์งฑ๊ตฌ',
hospitalName: '์˜ค์ˆ˜๋ณ‘์›',
issuedAt: Date.now(),
},
];
// ์ž„์‹œ: QR์— ๋‹ด์„ JSON ๋ฌธ์ž์—ด
const qrData = JSON.stringify(userVC);
//const qrData = JSON.stringify(userVC);

const navigation = useNavigation();

Expand All @@ -39,37 +52,7 @@ const MainPage = () => {
source={require('../assets/images/logoGreen.png')}
resizeMode="contain" // ์ด๋ฏธ์ง€ ๋น„์œจ ์œ ์ง€
/>
<View style={styles.shadowWrapper}>
<View style={styles.cardContainer}>
<Image
style={styles.backgroundImage}
source={require('../assets/images/mainBackground.png')}
resizeMode="contain" // ์ด๋ฏธ์ง€ ๋น„์œจ ์œ ์ง€
/>
{hasAccessAuthority ? (
<>
<Text style={styles.qrTitle}>์ž„์‹œ ์ถœ์ž… QR</Text>
<QRCode
value={qrData}
size={140}
color={colors.black}
backgroundColor={colors.white}
/>
<Text style={styles.userName}>{userVC.userName}</Text>
<Text style={styles.hospital}>{userVC.hospital1}</Text>
<Text style={styles.hospital}>{userVC.hospital2}</Text>
<Text style={styles.hospital}>{userVC.hospital3}</Text>
</>
) : (
<>
<Text style={styles.cardText}>๋“ฑ๋ก๋œ ์ถœ์ž… ๊ถŒํ•œ์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.</Text>
<Text style={styles.cardSubText}>
๋ฐฉ๋ฌธ ์‹ ์ฒญ ๋ฒ„ํŠผ์„ ๋ˆŒ๋Ÿฌ ์ถœ์ž… ๊ถŒํ•œ์„ ์‹ ์ฒญํ•ด์ฃผ์„ธ์š”.
</Text>
</>
)}
</View>
</View>
<QrCards hasAccessAuthority={hasAccessAuthority} userVC={userVC} />
<View style={styles.buttonContainer}>
<NormalButton title="๋ฐฉ๋ฌธ ์‹ ์ฒญ" length="short" onPressHandler={navigateToAccessList} />
<NormalButton title="๋งˆ์ด ํŽ˜์ด์ง€" length="short" onPressHandler={navigateToMyPage} />
Expand Down
Loading