1- import { View , Text } from 'react-native' ;
1+ import { useState } from 'react' ;
2+ import { View , Text , TouchableOpacity , StyleSheet } from 'react-native' ;
23import {
34 HyperInit ,
45} from '@juspay-tech/react-native-hyperswitch' ;
5- import PaymentScreen from './PaymentScreen' ;
6+ import UIScreen from './UIScreen' ;
7+ import HeadlessScreen from './HeadlessScreen' ;
8+
9+ type TabType = 'ui' | 'headless' ;
610
711export default function App ( ) {
12+ const [ activeTab , setActiveTab ] = useState < TabType > ( 'ui' ) ;
13+
814 const publishableKey = process . env . HYPERSWITCH_PUBLISHABLE_KEY ;
915 const profileId = process . env . PROFILE_ID ;
1016
@@ -15,19 +21,93 @@ export default function App() {
1521
1622 if ( ! publishableKey || ! profileId ) {
1723 return (
18- < View style = { { flex : 1 , alignItems : 'center' , justifyContent : 'center' } } >
24+ < View style = { styles . centerContainer } >
1925 < Text > Configure env and restart Metro server</ Text >
2026 </ View >
2127 ) ;
2228 }
2329
2430 if ( ! hyperPromise ) {
2531 return (
26- < View style = { { flex : 1 , alignItems : 'center' , justifyContent : 'center' } } >
32+ < View style = { styles . centerContainer } >
2733 < Text > Initializing...</ Text >
2834 </ View >
2935 ) ;
3036 }
3137
32- return ( < PaymentScreen hyperPromise = { hyperPromise } /> ) ;
33- }
38+ return (
39+ < View style = { styles . container } >
40+ < View style = { styles . tabContainer } >
41+ < TouchableOpacity
42+ style = { [ styles . tab , activeTab === 'ui' && styles . activeTab ] }
43+ onPress = { ( ) => setActiveTab ( 'ui' ) }
44+ >
45+ < Text style = { [ styles . tabText , activeTab === 'ui' && styles . activeTabText ] } >
46+ UI Mode
47+ </ Text >
48+ </ TouchableOpacity >
49+ < TouchableOpacity
50+ style = { [ styles . tab , activeTab === 'headless' && styles . activeTab ] }
51+ onPress = { ( ) => setActiveTab ( 'headless' ) }
52+ >
53+ < Text style = { [ styles . tabText , activeTab === 'headless' && styles . activeTabText ] } >
54+ Headless Mode
55+ </ Text >
56+ </ TouchableOpacity >
57+ </ View >
58+
59+ < View style = { styles . content } >
60+ { activeTab === 'ui' ? (
61+ < UIScreen hyperPromise = { hyperPromise } />
62+ ) : (
63+ < HeadlessScreen hyperPromise = { hyperPromise } />
64+ ) }
65+ </ View >
66+ </ View >
67+ ) ;
68+ }
69+
70+ const styles = StyleSheet . create ( {
71+ container : {
72+ flex : 1 ,
73+ } ,
74+ centerContainer : {
75+ flex : 1 ,
76+ alignItems : 'center' ,
77+ justifyContent : 'center' ,
78+ } ,
79+ subText : {
80+ fontSize : 12 ,
81+ color : '#666' ,
82+ marginTop : 8 ,
83+ } ,
84+ tabContainer : {
85+ flexDirection : 'row' ,
86+ backgroundColor : '#f5f5f5' ,
87+ paddingTop : 50 ,
88+ borderBottomWidth : 1 ,
89+ borderBottomColor : '#ddd' ,
90+ } ,
91+ tab : {
92+ flex : 1 ,
93+ paddingVertical : 16 ,
94+ alignItems : 'center' ,
95+ } ,
96+ activeTab : {
97+ backgroundColor : '#fff' ,
98+ borderBottomWidth : 2 ,
99+ borderBottomColor : '#007AFF' ,
100+ } ,
101+ tabText : {
102+ fontSize : 16 ,
103+ color : '#666' ,
104+ fontWeight : '500' ,
105+ } ,
106+ activeTabText : {
107+ color : '#007AFF' ,
108+ fontWeight : '600' ,
109+ } ,
110+ content : {
111+ flex : 1 ,
112+ } ,
113+ } ) ;
0 commit comments