Skip to content

Commit

Permalink
Merge pull request #20 from farzin-fs/refactor
Browse files Browse the repository at this point in the history
refactor: ♻️ improvements
  • Loading branch information
farzinmirzaie authored Sep 9, 2022
2 parents 8dc0be5 + eef027d commit c5eaed2
Show file tree
Hide file tree
Showing 62 changed files with 650 additions and 383 deletions.
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
arrowParens: 'avoid',
bracketSameLine: true,
bracketSpacing: false,
bracketSpacing: true,
singleQuote: true,
trailingComma: 'all',
};
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "animex",
"displayName": "animex"
}
}
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AppRegistry} from 'react-native';
import { AppRegistry } from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
import { name as appName } from './app.json';
import 'react-native-gesture-handler';

AppRegistry.registerComponent(appName, () => App);
4 changes: 2 additions & 2 deletions index.web.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {AppRegistry} from 'react-native';
import { AppRegistry } from 'react-native';
import App from './src/App';
import {name as appName} from './app.json';
import { name as appName } from './app.json';

if (module.hot) {
module.hot.accept();
Expand Down
12 changes: 12 additions & 0 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,8 @@ PODS:
- React-jsi (= 0.70.0)
- React-logger (= 0.70.0)
- React-perflogger (= 0.70.0)
- RNCAsyncStorage (1.17.10):
- React-Core
- RNGestureHandler (2.6.0):
- React-Core
- RNReanimated (2.10.0):
Expand Down Expand Up @@ -388,6 +390,8 @@ PODS:
- RNScreens (3.17.0):
- React-Core
- React-RCTImage
- RNVectorIcons (9.2.0):
- React-Core
- SocketRocket (0.6.0)
- Yoga (1.14.0)
- YogaKit (1.18.1):
Expand Down Expand Up @@ -450,9 +454,11 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- RNGestureHandler (from `../node_modules/react-native-gesture-handler`)
- RNReanimated (from `../node_modules/react-native-reanimated`)
- RNScreens (from `../node_modules/react-native-screens`)
- RNVectorIcons (from `../node_modules/react-native-vector-icons`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
Expand Down Expand Up @@ -538,12 +544,16 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/runtimeexecutor"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNCAsyncStorage:
:path: "../node_modules/@react-native-async-storage/async-storage"
RNGestureHandler:
:path: "../node_modules/react-native-gesture-handler"
RNReanimated:
:path: "../node_modules/react-native-reanimated"
RNScreens:
:path: "../node_modules/react-native-screens"
RNVectorIcons:
:path: "../node_modules/react-native-vector-icons"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

Expand Down Expand Up @@ -593,9 +603,11 @@ SPEC CHECKSUMS:
React-RCTVibration: 5499b77c0fd57f346a5f0b36bb79fdb020d17d3e
React-runtimeexecutor: 80c195ffcafb190f531fdc849dc2d19cb4bb2b34
ReactCommon: de55f940495d7bf87b5d7bf55b5b15cdd50d7d7b
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
RNGestureHandler: 920eb17f5b1e15dae6e5ed1904045f8f90e0b11e
RNReanimated: 60e291d42c77752a0f6d6f358387bdf225a87c6e
RNScreens: 0df01424e9e0ed7827200d6ed1087ddd06c493f9
RNVectorIcons: fcc2f6cb32f5735b586e66d14103a74ce6ad61f8
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
Yoga: 82c9e8f652789f67d98bed5aef9d6653f71b04a9
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
2 changes: 0 additions & 2 deletions ios/animex.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
574DA0B028C9BE8B006172BD /* Ionicons.ttf in Resources */ = {isa = PBXBuildFile; fileRef = 574DA0AF28C9BE8B006172BD /* Ionicons.ttf */; };
7699B88040F8A987B510C191 /* libPods-animex-animexTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 19F6CBCC0A4E27FBF8BF4A61 /* libPods-animex-animexTests.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
/* End PBXBuildFile section */
Expand Down Expand Up @@ -255,7 +254,6 @@
files = (
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */,
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
574DA0B028C9BE8B006172BD /* Ionicons.ttf in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
},
"dependencies": {
"@react-native-async-storage/async-storage": "^1.17.10",
"@react-navigation/bottom-tabs": "^6.3.3",
"@react-navigation/drawer": "^6.4.4",
"@react-navigation/native": "^6.0.12",
"@react-navigation/native-stack": "^6.8.0",
"@reduxjs/toolkit": "^1.8.5",
"react": "18.1.0",
"react-native": "0.70.0",
"react-native-gesture-handler": "^2.6.0",
Expand All @@ -24,6 +26,8 @@
"react-native-screens": "^3.17.0",
"react-native-vector-icons": "^9.2.0",
"react-native-web": "^0.18.9",
"react-redux": "^8.0.2",
"redux-persist": "^6.0.0",
"styled-components": "^5.3.5"
},
"devDependencies": {
Expand Down
12 changes: 6 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React from 'react';
import {StatusBar} from 'react-native';
import {ThemeProvider} from 'styled-components/native';
import {useDarkMode} from './hooks';
import { StatusBar } from 'react-native';
import { ThemeProvider } from 'styled-components/native';
import { useDarkMode } from './hooks';
import Navigation from './navigation';
import {StoreProvider} from './stores';
import {darkTheme, lightTheme} from './themes';
import { StoreProvider } from './stores';
import { darkTheme, lightTheme } from './themes';

const App = () => {
const App: React.FC = () => {
const isDarkMode = useDarkMode();

return (
Expand Down
22 changes: 13 additions & 9 deletions src/components/AnimeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,37 @@
import React from 'react';
import styled from 'styled-components/native';
import {TAnime} from '../types';
import { Image, TouchableOpacity, View } from 'react-native';
import styled from '../themes';
import { TAnime } from '../types';
import TextPrimary from './TextPrimary';
import TextSecondary from './TextSecondary';

const Container = styled.TouchableOpacity`
const Container = styled(TouchableOpacity)<Pick<TProps, 'flex'>>`
${({ flex }) => (flex === 1 ? 'flex: 1' : '')};
width: 100%;
flex-direction: row;
padding: 12px;
`;

const DetailsContainer = styled.View`
const DetailsContainer = styled(View)`
flex: 1;
padding-left: 12px;
`;

const Cover = styled.Image`
const Cover = styled(Image)`
width: 75px;
height: 115px;
background-color: ${({theme}) => theme.colors.textSecondary};
background-color: ${({ theme }) => theme.colors.textSecondary};
`;

type TProps = {
data: TAnime;
onPress: () => void;
flex?: number;
};

const AnimeCard: React.FC<TProps> = ({data, onPress}) => (
<Container onPress={onPress}>
<Cover source={{uri: data.images.jpg.image_url}} />
const AnimeCard: React.FC<TProps> = ({ data, onPress, flex }) => (
<Container onPress={onPress} flex={flex}>
<Cover source={{ uri: data.images.jpg.image_url }} />
<DetailsContainer>
<TextPrimary>{data.title}</TextPrimary>
{data.rating && <TextSecondary>{data.rating}</TextSecondary>}
Expand Down
61 changes: 38 additions & 23 deletions src/components/AnimeDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
import React from 'react';
import styled from 'styled-components/native';
import {TAnime} from '../types';
import { useWindowDimensions, View } from 'react-native';
import styled from '../themes';
import { TAnime } from '../types';
import CoverImage from './CoverImage';
import Divider from './Divider';
import Spacer from './Spacer';
import TextPrimary from './TextPrimary';
import TextSecondary from './TextSecondary';

const Container = styled.View`
const Container = styled(View)<{ dir: string }>`
flex-direction: ${({ dir }) => dir};
`;

const DetailsContainer = styled(View)`
flex: 1;
padding: 12px;
`;

type TProps = {
data: TAnime;
};

const AnimeDetails: React.FC<TProps> = ({data}) => (
<>
<CoverImage uri={data.images.jpg.large_image_url} />
<Container>
<TextPrimary>{data.title}</TextPrimary>
<TextSecondary>{data.title_japanese}</TextSecondary>
<Spacer />
<TextSecondary>{data.background}</TextSecondary>
<Spacer />
<Divider />
<Spacer />
<TextSecondary>Year: {data.year}</TextSecondary>
<TextSecondary>Status: {data.status}</TextSecondary>
<TextSecondary>Score: {data.score}</TextSecondary>
<TextSecondary>Rating: {data.rating}</TextSecondary>
<TextSecondary>Type: {data.type}</TextSecondary>
<TextSecondary>Episodes: {data.episodes}</TextSecondary>
<Spacer />
const AnimeDetails: React.FC<TProps> = ({ data }) => {
const window = useWindowDimensions();

return (
<Container dir={window.width <= 900 ? 'column' : 'row'}>
<CoverImage
uri={data.images.jpg.large_image_url}
initialWidth={window.width <= 900 ? window.width : window.width / 3}
/>
<DetailsContainer>
<TextPrimary>{data.title}</TextPrimary>
<TextSecondary>{data.title_japanese}</TextSecondary>
<Spacer />
{data.background && <TextSecondary>{data.background}</TextSecondary>}
{data.background && <Spacer />}
<Divider />
<Spacer />
{data.year && <TextSecondary>Year: {data.year}</TextSecondary>}
{data.status && <TextSecondary>Status: {data.status}</TextSecondary>}
{data.score && <TextSecondary>Score: {data.score}</TextSecondary>}
{data.rating && <TextSecondary>Rating: {data.rating}</TextSecondary>}
{data.type && <TextSecondary>Type: {data.type}</TextSecondary>}
{data.episodes && (
<TextSecondary>Episodes: {data.episodes}</TextSecondary>
)}
<Spacer />
</DetailsContainer>
</Container>
</>
);
);
};

export default AnimeDetails;
19 changes: 13 additions & 6 deletions src/components/AnimeList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
StyleSheet,
useWindowDimensions,
} from 'react-native';
import {useTheme} from 'styled-components/native';
import {TAnime} from '../types';
import { useTheme } from 'styled-components/native';
import { TAnime } from '../types';
import AnimeCard from './AnimeCard';
import Divider from './Divider';
import EmptyState from './EmptyState';
Expand All @@ -25,21 +25,27 @@ const AnimeList: React.FC<TProps> = ({
isLoading,
onLoadMore,
}) => {
const {colors} = useTheme();
const { colors } = useTheme();
const window = useWindowDimensions();
const columns = window.width <= 900 ? 1 : window.width <= 1300 ? 2 : 3;

return (
<FlatList
key={columns}
data={data}
keyExtractor={item => item.mal_id.toString()}
renderItem={({item}) => (
<AnimeCard data={item} onPress={() => onPress?.(item)} />
renderItem={({ item }) => (
<AnimeCard
data={item}
onPress={() => onPress?.(item)}
flex={columns !== 1 ? 1 : undefined}
/>
)}
ItemSeparatorComponent={() => <Divider size={'90%'} />}
style={
Platform.OS === 'web'
? {}
: {width: window.width, height: window.height}
: { width: window.width, height: window.height }
}
contentContainerStyle={styles.container}
ListEmptyComponent={() => (
Expand All @@ -50,6 +56,7 @@ const AnimeList: React.FC<TProps> = ({
}
onEndReached={onLoadMore}
onEndReachedThreshold={0.1}
numColumns={columns}
/>
);
};
Expand Down
5 changes: 3 additions & 2 deletions src/components/Center.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import styled from 'styled-components/native';
import { View } from 'react-native';
import styled from '../themes';

const Center = styled.View`
const Center = styled(View)`
flex: 1;
justify-content: center;
align-items: center;
Expand Down
33 changes: 24 additions & 9 deletions src/components/CoverImage.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import React from 'react';
import styled from 'styled-components/native';
import React, { useEffect, useState } from 'react';
import { Image } from 'react-native';
import styled from '../themes';

const Cover = styled.Image`
width: 100%;
height: 600px;
background-color: ${({theme}) => theme.colors.textSecondary};
const Cover = styled(Image)`
background-color: ${({ theme }) => theme.colors.textSecondary};
`;

type TProps = {
uri?: string;
initialWidth: number;
};

const CoverImage: React.FC<TProps> = ({uri}) => (
<Cover source={{uri: uri}} resizeMode="cover" />
);
const CoverImage: React.FC<TProps> = ({ uri, initialWidth = 300 }) => {
const [size, setSize] = useState({
width: initialWidth,
height: initialWidth * 1.5,
});

useEffect(() => {
if (uri) {
Image.getSize(uri, (width, height) => {
const ratio = Math.abs(height / width);

setSize({ width: size.width, height: size.width * ratio });
});
}
}, [uri, size]);

return <Cover source={{ uri: uri }} resizeMode="cover" style={size} />;
};

export default CoverImage;
Loading

0 comments on commit c5eaed2

Please sign in to comment.