-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
196 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,122 @@ | ||
import React from "react"; | ||
import { Button, StyleSheet, Text, View } from "react-native"; | ||
import { Pressable, ScrollView, StyleSheet, Text, View } from "react-native"; | ||
import React, { useState } from "react"; | ||
import { | ||
login, | ||
logout, | ||
getProfile as getKakaoProfile, | ||
shippingAddresses as getKakaoShippingAddresses, | ||
unlink, | ||
} from "@react-native-seoul/kakao-login"; | ||
|
||
export type Props = { | ||
name: string; | ||
baseEnthusiasmLevel?: number; | ||
}; | ||
const App = () => { | ||
const [result, setResult] = useState<string>(""); | ||
|
||
const signInWithKakao = async (): Promise<void> => { | ||
try { | ||
const token = await login(); | ||
setResult(JSON.stringify(token)); | ||
} catch (err) { | ||
console.error("login err", err); | ||
} | ||
}; | ||
|
||
const signOutWithKakao = async (): Promise<void> => { | ||
try { | ||
const message = await logout(); | ||
|
||
setResult(message); | ||
} catch (err) { | ||
console.error("signOut error", err); | ||
} | ||
}; | ||
|
||
const getProfile = async (): Promise<void> => { | ||
try { | ||
const profile = await getKakaoProfile(); | ||
|
||
setResult(JSON.stringify(profile)); | ||
} catch (err) { | ||
console.error("signOut error", err); | ||
} | ||
}; | ||
|
||
const getShippingAddresses = async (): Promise<void> => { | ||
try { | ||
const shippingAddresses = await getKakaoShippingAddresses(); | ||
|
||
const App: React.FC<Props> = ({ name, baseEnthusiasmLevel = 0 }) => { | ||
const [enthusiasmLevel, setEnthusiasmLevel] = | ||
React.useState(baseEnthusiasmLevel); | ||
setResult(JSON.stringify(shippingAddresses)); | ||
} catch (err) { | ||
console.error("signOut error", err); | ||
} | ||
}; | ||
|
||
const onIncrement = () => setEnthusiasmLevel(enthusiasmLevel + 1); | ||
const onDecrement = () => | ||
setEnthusiasmLevel(enthusiasmLevel > 0 ? enthusiasmLevel - 1 : 0); | ||
const unlinkKakao = async (): Promise<void> => { | ||
try { | ||
const message = await unlink(); | ||
|
||
const getExclamationMarks = (numChars: number) => | ||
numChars > 0 ? Array(numChars + 1).join("!") : ""; | ||
setResult(message); | ||
} catch (err) { | ||
console.error("signOut error", err); | ||
} | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Text style={styles.greeting}> | ||
Hello {name} | ||
{getExclamationMarks(enthusiasmLevel)} | ||
</Text> | ||
<View> | ||
<Button | ||
title="Increase enthusiasm" | ||
accessibilityLabel="increment" | ||
onPress={onIncrement} | ||
color="blue" | ||
/> | ||
<Button | ||
title="Decrease enthusiasm" | ||
accessibilityLabel="decrement" | ||
onPress={onDecrement} | ||
color="red" | ||
/> | ||
<View style={styles.resultContainer}> | ||
<ScrollView> | ||
<Text>{result}</Text> | ||
<View style={{ height: 100 }} /> | ||
</ScrollView> | ||
</View> | ||
<Pressable | ||
style={styles.button} | ||
onPress={() => { | ||
signInWithKakao(); | ||
}} | ||
> | ||
<Text style={styles.text}>카카오 로그인</Text> | ||
</Pressable> | ||
<Pressable style={styles.button} onPress={() => getProfile()}> | ||
<Text style={styles.text}>프로필 조회</Text> | ||
</Pressable> | ||
<Pressable style={styles.button} onPress={() => getShippingAddresses()}> | ||
<Text style={styles.text}>배송주소록 조회</Text> | ||
</Pressable> | ||
<Pressable style={styles.button} onPress={() => unlinkKakao()}> | ||
<Text style={styles.text}>링크 해제</Text> | ||
</Pressable> | ||
<Pressable style={styles.button} onPress={() => signOutWithKakao()}> | ||
<Text style={styles.text}>카카오 로그아웃</Text> | ||
</Pressable> | ||
</View> | ||
); | ||
}; | ||
|
||
export default App; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
height: "100%", | ||
justifyContent: "flex-end", | ||
alignItems: "center", | ||
justifyContent: "center", | ||
paddingBottom: 100, | ||
}, | ||
resultContainer: { | ||
flexDirection: "column", | ||
width: "100%", | ||
padding: 24, | ||
}, | ||
greeting: { | ||
fontSize: 20, | ||
fontWeight: "bold", | ||
margin: 16, | ||
button: { | ||
backgroundColor: "#FEE500", | ||
borderRadius: 40, | ||
borderWidth: 1, | ||
width: 250, | ||
height: 40, | ||
paddingHorizontal: 20, | ||
paddingVertical: 10, | ||
marginTop: 10, | ||
}, | ||
text: { | ||
textAlign: "center", | ||
}, | ||
}); | ||
|
||
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// SwiftBridge.swift | ||
// reactnativefirebase | ||
// | ||
// Created by Subin on 2023/09/01. | ||
// | ||
|
||
import Foundation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters