-
Notifications
You must be signed in to change notification settings - Fork 42
[MOB-10032] Example App: Login page #590
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
Merged
lposen
merged 15 commits into
2.0.0-alpha/master
from
2.0.0-alpha/MOB-10032-add-login-page
Nov 21, 2024
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
84bd88a
Add example .env file and update .gitignore for Iterable
lposen b9c5690
Update Android build configuration to use RNIterable properties
lposen 594ce59
Add Gradle wrapper properties and refactor RNIterableAPIPackage to us…
lposen 2d57408
Update package.json to add navigation dependencies and update Babel p…
lposen 3a836e2
Update example project configuration and add react-native-vector-icon…
lposen 3bd96d1
Add initial structure for navigation and components in example project
lposen a7b20e5
ran `bundle install`
lposen 6317f6b
ran `bundle install`
lposen 3c91a97
App builing and loading correctly
lposen 0491d27
Refactor app structure: remove old App component, add Main component …
lposen d90369f
Update README and environment setup: enhance instructions for API key…
lposen f82ed22
Merge branch '2.0.0-alpha/MOB-9671-fix-linting-issues' into 2.0.0-alp…
lposen 539e4b5
Merge branch '2.0.0-alpha/master' into 2.0.0-alpha/MOB-10032-add-logi…
lposen 534c676
Fixed typo, as per PR review
lposen 5b442a9
Fixed typo, as per README
lposen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 +1,5 @@ | ||
| import { AppRegistry } from 'react-native'; | ||
| import App from './src/App'; | ||
| import App from './src'; | ||
| import { name as appName } from './app.json'; | ||
|
|
||
| AppRegistry.registerComponent(appName, () => App); |
This file contains hidden or 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,5 @@ | ||
| import { Route } from '../../constants'; | ||
|
|
||
| export const routeIcon = { | ||
| [Route.User]: 'person-outline', | ||
| }; |
This file contains hidden or 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,33 @@ | ||
| import { createNativeStackNavigator } from '@react-navigation/native-stack'; | ||
|
|
||
| import { Route } from '../../constants/routes'; | ||
| import { useIterableApp } from '../../hooks/useIterableApp'; | ||
| import { Login } from '../Login'; | ||
| import { Main } from './Main'; | ||
| import type { RootStackParamList } from '../../types'; | ||
|
|
||
| const Stack = createNativeStackNavigator<RootStackParamList>(); | ||
|
|
||
| export const App = () => { | ||
| const { isLoggedIn } = useIterableApp(); | ||
|
|
||
| return ( | ||
| <Stack.Navigator> | ||
| {isLoggedIn ? ( | ||
| <Stack.Screen | ||
| name={Route.Main} | ||
| component={Main} | ||
| options={{ headerShown: false }} | ||
| /> | ||
| ) : ( | ||
| <Stack.Screen | ||
| name={Route.Login} | ||
| component={Login} | ||
| options={{ headerShown: false }} | ||
| /> | ||
| )} | ||
| </Stack.Navigator> | ||
| ); | ||
| }; | ||
|
|
||
| export default App; |
This file contains hidden or 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,5 @@ | ||
| import Icon from 'react-native-vector-icons/Ionicons'; | ||
|
|
||
| export const getIcon = (name: string, props: Record<string, any>) => ( | ||
| <Icon name={name} {...props} /> | ||
| ); |
This file contains hidden or 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,31 @@ | ||
| import { createBottomTabNavigator } from '@react-navigation/bottom-tabs'; | ||
|
|
||
| import { colors, Route } from '../../constants'; | ||
| import type { MainScreenParamList } from '../../types'; | ||
| import { routeIcon } from './App.constants'; | ||
| import { getIcon } from './App.utils'; | ||
| import { User } from '../User'; | ||
|
|
||
| const Tab = createBottomTabNavigator<MainScreenParamList>(); | ||
|
|
||
| export const Main = () => { | ||
| return ( | ||
| <> | ||
| <Tab.Navigator | ||
| screenOptions={({ route }) => { | ||
| const iconName = routeIcon[route.name as keyof typeof routeIcon]; | ||
| return { | ||
| tabBarIcon: (props) => getIcon(iconName as string, props), | ||
| tabBarActiveTintColor: colors.brandPurple, | ||
| tabBarInactiveTintColor: colors.textSecondary, | ||
| headerShown: false, | ||
| }; | ||
| }} | ||
| > | ||
| <Tab.Screen name={Route.User} component={User} /> | ||
| </Tab.Navigator> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default Main; |
This file contains hidden or 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,2 @@ | ||
| export * from './App'; | ||
| export { default } from './App'; |
This file contains hidden or 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,40 @@ | ||
| import { StyleSheet, type ViewStyle } from 'react-native'; | ||
| import { | ||
| appName, | ||
| buttonBlock, | ||
| buttonDisabled, | ||
| buttonText, | ||
| buttonTextDisabled, | ||
| container, | ||
| input, | ||
| label, | ||
| subtitle, | ||
| title, | ||
| } from '../../constants'; | ||
|
|
||
| const setButton = (buttonToSet: ViewStyle = {}) => ({ | ||
| ...buttonBlock, | ||
| ...buttonToSet, | ||
| marginTop: 32, | ||
| }); | ||
|
|
||
| export const styles = StyleSheet.create({ | ||
| loginScreenContainer: { | ||
| ...container, | ||
| backgroundColor: 'white', | ||
| }, | ||
| loadingContainer: { | ||
| flex: 1, | ||
| justifyContent: 'center', | ||
| }, | ||
| formContainer: { marginTop: 24 }, | ||
| appName, | ||
| title, | ||
| subtitle, | ||
| input: { ...input, marginBottom: 15 }, | ||
| button: setButton(), | ||
| buttonDisabled: setButton(buttonDisabled), | ||
| buttonText, | ||
| buttonTextDisabled, | ||
| label, | ||
| }); | ||
This file contains hidden or 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,73 @@ | ||
| import { | ||
| ActivityIndicator, | ||
| Pressable, | ||
| Text, | ||
| TextInput, | ||
| View, | ||
| } from 'react-native'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import { colors, type Route } from '../../constants'; | ||
| import { useIterableApp } from '../../hooks'; | ||
| import type { RootStackScreenProps } from '../../types'; | ||
| import { styles } from './Login.styles'; | ||
|
|
||
| export const Login = ({ navigation }: RootStackScreenProps<Route.Login>) => { | ||
| const { apiKey, setApiKey, userId, setUserId, initialize, loginInProgress } = | ||
| useIterableApp(); | ||
| const loginIsEnabled = useMemo(() => apiKey && userId, [apiKey, userId]); | ||
|
|
||
| return ( | ||
| <View style={styles.loginScreenContainer}> | ||
| {loginInProgress ? ( | ||
| <View style={styles.loadingContainer}> | ||
| <ActivityIndicator size="large" color={colors.brandPurple} /> | ||
| </View> | ||
| ) : ( | ||
| <> | ||
| <Text style={styles.appName}>Iterable</Text> | ||
| <Text style={styles.title}>Sign in to continue</Text> | ||
| <Text style={styles.subtitle}> | ||
| Example app for React Native developers | ||
| </Text> | ||
| <View style={styles.formContainer}> | ||
| <Text style={styles.label}>API key</Text> | ||
| <TextInput | ||
| style={styles.input} | ||
| onChangeText={setApiKey} | ||
| value={apiKey} | ||
| placeholder="eg: 1234567890abcdefg1234567890hijkl" | ||
| autoCapitalize="none" | ||
| autoCorrect={false} | ||
| /> | ||
| <Text style={styles.label}>Email address or User Id</Text> | ||
| <TextInput | ||
| style={styles.input} | ||
| onChangeText={setUserId} | ||
| value={userId} | ||
| placeholder="eg: [email protected] or 1234567890" | ||
| autoCapitalize="none" | ||
| autoCorrect={false} | ||
| autoComplete="email" | ||
| /> | ||
| <Pressable | ||
| style={loginIsEnabled ? styles.button : styles.buttonDisabled} | ||
| disabled={!loginIsEnabled} | ||
| onPressOut={() => initialize(navigation)} | ||
| > | ||
| <Text | ||
| style={ | ||
| loginIsEnabled ? styles.buttonText : styles.buttonTextDisabled | ||
| } | ||
| > | ||
| Login | ||
| </Text> | ||
| </Pressable> | ||
| </View> | ||
| </> | ||
| )} | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default Login; |
This file contains hidden or 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,2 @@ | ||
| export * from './Login'; | ||
| export { default } from './Login'; |
This file contains hidden or 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,21 @@ | ||
| import { StyleSheet, type TextStyle } from 'react-native'; | ||
| import { appNameSmall, button, buttonText, container } from '../../constants'; | ||
|
|
||
| const text: TextStyle = { | ||
| textAlign: 'center', | ||
| marginBottom: 20, | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container, | ||
| appName: appNameSmall, | ||
| button, | ||
| buttonText, | ||
| secondaryButton: { | ||
| ...button, | ||
| backgroundColor: 'gray', | ||
| }, | ||
| text, | ||
| }); | ||
|
|
||
| export default styles; |
This file contains hidden or 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,31 @@ | ||
| import { Iterable } from '@iterable/react-native-sdk'; | ||
| import { useEffect, useState } from 'react'; | ||
| import { Text, TouchableOpacity, View } from 'react-native'; | ||
|
|
||
| import { useIterableApp } from '../../hooks'; | ||
| import styles from './User.styles'; | ||
|
|
||
| export const User = () => { | ||
| const { logout, isLoggedIn } = useIterableApp(); | ||
| const [loggedInAs, setLoggedInAs] = useState<string>(''); | ||
|
|
||
| useEffect(() => { | ||
| if (isLoggedIn) { | ||
| Iterable.getEmail().then((email) => setLoggedInAs(email || '')); | ||
| } else { | ||
| setLoggedInAs(''); | ||
| } | ||
| }, [isLoggedIn]); | ||
|
|
||
| return ( | ||
| <View style={styles.container}> | ||
| <Text style={styles.appName}>Welcome Iterator</Text> | ||
| <Text style={styles.text}>Logged in as {loggedInAs}</Text> | ||
| <TouchableOpacity style={styles.secondaryButton} onPress={logout}> | ||
| <Text style={styles.buttonText}>Logout</Text> | ||
| </TouchableOpacity> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| export default User; |
This file contains hidden or 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,2 @@ | ||
| export * from './User'; | ||
| export { default } from './User'; |
This file contains hidden or 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,2 @@ | ||
| export * from './routes'; | ||
| export * from './styles'; | ||
evantk91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
This file contains hidden or 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,5 @@ | ||
| export enum Route { | ||
| Login = 'Login', | ||
| Main = 'Main', | ||
| User = 'User', | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.