Add responsive design

Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
2023-07-09 20:43:11 +03:00
parent 3c797bf02d
commit 3ff8521771
5 changed files with 49 additions and 29 deletions

View File

@@ -1,4 +1,4 @@
import React, { JSX } from 'react'; import React from 'react';
import { StatusBar, useColorScheme } from 'react-native'; import { StatusBar, useColorScheme } from 'react-native';
import { PaperProvider } from 'react-native-paper'; import { PaperProvider } from 'react-native-paper';
import { SafeAreaProvider } from 'react-native-safe-area-context'; import { SafeAreaProvider } from 'react-native-safe-area-context';
@@ -8,7 +8,7 @@ import { Meme, Tag } from './database';
import NavigationContainer from './navigation'; import NavigationContainer from './navigation';
import { SettingsProvider } from './contexts/settings'; import { SettingsProvider } from './contexts/settings';
function App(): JSX.Element { function App() {
const colorScheme = useColorScheme(); const colorScheme = useColorScheme();
const isDarkMode = colorScheme === 'dark'; const isDarkMode = colorScheme === 'dark';
const theme = isDarkMode ? darkTheme : lightTheme; const theme = isDarkMode ? darkTheme : lightTheme;

View File

@@ -2,10 +2,11 @@ import * as React from 'react';
import { StyleSheet } from 'react-native'; import { StyleSheet } from 'react-native';
import { FAB, Portal } from 'react-native-paper'; import { FAB, Portal } from 'react-native-paper';
import { noOp } from '../constants'; import { noOp } from '../constants';
import { verticalScale } from '../styles';
const styles = StyleSheet.create({ const styles = StyleSheet.create({
fab: { fab: {
paddingBottom: 90, paddingBottom: verticalScale(75),
}, },
}); });

View File

@@ -1,17 +1,7 @@
import React from 'react'; import React from 'react';
import { StyleProp, StyleSheet, View, ViewStyle } from 'react-native'; import { StyleProp, View, ViewStyle } from 'react-native';
import { useTheme } from 'react-native-paper'; import { useTheme } from 'react-native-paper';
import styles from '../styles';
const styles = StyleSheet.create({
container: {
flex: 1,
padding: '5%',
},
centered: {
justifyContent: 'center',
alignItems: 'center',
},
});
const PaddedView = ({ const PaddedView = ({
children, children,
@@ -21,11 +11,17 @@ const PaddedView = ({
children: React.ReactNode; children: React.ReactNode;
style?: StyleProp<ViewStyle>; style?: StyleProp<ViewStyle>;
centered?: boolean; centered?: boolean;
}): React.JSX.Element => { }) => {
const { colors } = useTheme(); const { colors } = useTheme();
return ( return (
<View style={[styles.container, centered && styles.centered, { backgroundColor: colors.background }, style]}> <View
style={[
styles.padding,
centered && styles.centered,
{ backgroundColor: colors.background },
style,
]}>
{children} {children}
</View> </View>
); );

View File

@@ -8,6 +8,7 @@ import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { BottomNavigation, useTheme } from 'react-native-paper'; import { BottomNavigation, useTheme } from 'react-native-paper';
import { Home, Search, Tags, Settings } from './screens'; import { Home, Search, Tags, Settings } from './screens';
import ActionButton from './components/actionButton'; import ActionButton from './components/actionButton';
import { horizontalScale } from './styles';
function NavigationContainer() { function NavigationContainer() {
const TabNavigator = createBottomTabNavigator(); const TabNavigator = createBottomTabNavigator();
@@ -56,7 +57,11 @@ function NavigationContainer() {
renderIcon={({ route, focused, color }) => { renderIcon={({ route, focused, color }) => {
const { options } = descriptors[route.key]; const { options } = descriptors[route.key];
if (options.tabBarIcon) { if (options.tabBarIcon) {
return options.tabBarIcon({ focused, color, size: 24 }); return options.tabBarIcon({
focused,
color,
size: horizontalScale(20),
});
} }
}} }}
getLabelText={({ route }) => { getLabelText={({ route }) => {
@@ -69,8 +74,8 @@ function NavigationContainer() {
name="Home" name="Home"
component={Home} component={Home}
options={{ options={{
tabBarIcon: ({ color }) => ( tabBarIcon: ({ color, size }) => (
<FontAwesome5 name="home" color={color} size={20} /> <FontAwesome5 name="home" color={color} size={size} />
), ),
}} }}
/> />
@@ -78,8 +83,8 @@ function NavigationContainer() {
name="Search" name="Search"
component={Search} component={Search}
options={{ options={{
tabBarIcon: ({ color }) => ( tabBarIcon: ({ color, size }) => (
<FontAwesome5 name="search" color={color} size={20} /> <FontAwesome5 name="search" color={color} size={size} />
), ),
}} }}
/> />
@@ -87,8 +92,8 @@ function NavigationContainer() {
name="Tags" name="Tags"
component={Tags} component={Tags}
options={{ options={{
tabBarIcon: ({ color }) => ( tabBarIcon: ({ color, size }) => (
<FontAwesome5 name="tags" color={color} size={20} /> <FontAwesome5 name="tags" color={color} size={size} />
), ),
}} }}
/> />
@@ -96,8 +101,8 @@ function NavigationContainer() {
name="Settings" name="Settings"
component={Settings} component={Settings}
options={{ options={{
tabBarIcon: ({ color }) => ( tabBarIcon: ({ color, size }) => (
<FontAwesome5 name="cog" color={color} size={20} /> <FontAwesome5 name="cog" color={color} size={size} />
), ),
}} }}
/> />

View File

@@ -1,17 +1,35 @@
import { StyleSheet } from 'react-native'; import { StyleSheet, Dimensions } from 'react-native';
const { width, height } = Dimensions.get('window');
const guidelineBaseWidth = 350;
const guidelineBaseHeight = 680;
const horizontalScale = (size: number) => (width / guidelineBaseWidth) * size;
const verticalScale = (size: number) => (height / guidelineBaseHeight) * size;
const moderateScale = (size: number, factor = 0.5) =>
size + (horizontalScale(size) - size) * factor;
const styles = StyleSheet.create({ const styles = StyleSheet.create({
marginBottom: { marginBottom: {
marginBottom: 15, marginBottom: verticalScale(5),
},
padding: {
padding: '5%',
}, },
spaceBetweenHorizontal: { spaceBetweenHorizontal: {
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
}, },
centered: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
centerText: { centerText: {
textAlign: 'center', textAlign: 'center',
}, },
}); });
export default styles; export { horizontalScale, verticalScale, moderateScale, styles as default };