Skip to content
This repository has been archived by the owner on Dec 8, 2022. It is now read-only.

Status bar refactoring and other minor changes #104

Merged
merged 3 commits into from
May 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/layouts/HeaderLayout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export default function HeaderLayout({
);
case 'search':
return (
<ActionButton onPress={() => navigation.goBack()}>
<ActionButton>
<Ionicons
name="search"
size={24}
Expand All @@ -103,7 +103,7 @@ export default function HeaderLayout({
);
case 'options':
return (
<ActionButton onPress={() => null}>
<ActionButton>
<MaterialCommunityIcons
name="dots-vertical"
size={24}
Expand Down
29 changes: 18 additions & 11 deletions src/pages/Animal/Details/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
// Package imports.
import React, { useLayoutEffect, useState } from 'react';
import React, { useCallback, useState } from 'react';
import { setStatusBarBackgroundColor } from 'expo-status-bar';
import Lodash from 'lodash';
import {
ActivityIndicator, Alert, Dimensions, ImageSourcePropType, ViewProps,
} from 'react-native';
import Carousel, { Pagination } from 'react-native-snap-carousel';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import {
RouteProp,
useFocusEffect,
useNavigation,
useRoute,
} from '@react-navigation/native';

// Service imports.
import adoptionAPI from '../../../services/adoption/api';
Expand Down Expand Up @@ -95,13 +100,14 @@ export default function AnimalDetails() : JSX.Element {
TitleText,
} = styledComponents;

// Function declaration.
function booleanToString(value : boolean) : string {
if (value === true) return 'Sim';
return 'Não';
}
// Callback declaration.
const determinePageBehavior = useCallback(() : void => {
// Function declaration.
function booleanToString(value : boolean) : string {
if (value === true) return 'Sim';
return 'Não';
}

function determinePageBehavior() : void {
function describeAnimalAdoptionRequirements(
adoptionRequirements : AnimalTypes.AdoptionRequirements,
) : string {
Expand Down Expand Up @@ -167,6 +173,7 @@ export default function AnimalDetails() : JSX.Element {
);
}

// Callback implementation.
animalAPI.getAnimal(animalUID)
.then(async (animal) => {
const animalData = animal.data();
Expand Down Expand Up @@ -231,7 +238,6 @@ export default function AnimalDetails() : JSX.Element {
asyncAction={false}
callback={async () => {
navigation.navigate('Interested', { animalUID });
// console.log((await adoptionAPI.getInterestedIn(animal.ref)));
}}
>
<ButtonText>Ver interessados</ButtonText>
Expand Down Expand Up @@ -375,16 +381,17 @@ export default function AnimalDetails() : JSX.Element {
}
})
.catch(() => errorAlert());
}
}, [animalUID, navigation]);

// Function declaration.
function displayAnimalImage(
{ item } : CarouselTypes.CarouselRenderItem,
) : JSX.Element {
return (<AnimalImage source={item} />);
}

// Page effects.
useLayoutEffect(determinePageBehavior, [animalUID, navigation]);
useFocusEffect(determinePageBehavior);

// JSX returned.
return (
Expand Down
12 changes: 7 additions & 5 deletions src/pages/Animal/Feed/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useLayoutEffect } from 'react';
import React, { useCallback } from 'react';
import { setStatusBarBackgroundColor } from 'expo-status-bar';

import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';

import { useNavigation } from '@react-navigation/native';
import { useFocusEffect, useNavigation } from '@react-navigation/native';

import HeaderLayout from '../../../layouts/HeaderLayout';

Expand Down Expand Up @@ -36,9 +36,11 @@ import { filterPaginated } from '../../../services/paginated/api';
const FeedPets = (): JSX.Element => {
const navigation = useNavigation();

useLayoutEffect(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarSecondaryDark, false);
}, [navigation]);
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarSecondaryDark, true);
}, []),
);

const animalKey = (animalItem: Animal): string => animalItem.id;

Expand Down
26 changes: 17 additions & 9 deletions src/pages/Animal/Interested/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import { RouteProp, useNavigation, useRoute } from '@react-navigation/native';
import React, { useCallback, useEffect, useState } from 'react';
import {
RouteProp,
useFocusEffect,
useNavigation,
useRoute,
} from '@react-navigation/native';
import { setStatusBarBackgroundColor } from 'expo-status-bar';
import {
ActivityIndicator, Text, Image, TouchableOpacity, Alert,
} from 'react-native';
import React, {
useCallback, useEffect, useLayoutEffect, useState,
} from 'react';
import { fromUnixTime, differenceInYears } from 'date-fns';
import InfiniteScroll from '../../../components/InfiniteScroll';
import { Theme } from '../../../constants';
Expand Down Expand Up @@ -105,9 +108,11 @@ const Interested = (): JSX.Element => {
});
}, [fetchAnimal]);

useLayoutEffect(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimaryDark, false);
}, [navigation]);
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimaryDark, true);
}, []),
);

return (
loading
Expand Down Expand Up @@ -172,8 +177,11 @@ const Interested = (): JSX.Element => {
if (animal) {
adoptionAPI.transferAnimalTo(animal, interestedUser.ref);
navigation.reset({
index: 0,
routes: [{ name: 'Home' }],
index: 1,
routes: [
{ name: 'Home' },
{ name: 'MyPets' },
],
});
Alert.alert('Transferência realizada com sucesso!');
}
Expand Down
17 changes: 10 additions & 7 deletions src/pages/Animal/MyPets/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useLayoutEffect } from 'react';
import React, { useCallback } from 'react';
import { setStatusBarBackgroundColor } from 'expo-status-bar';

import MaterialIcons from 'react-native-vector-icons/MaterialIcons';

import { useNavigation } from '@react-navigation/native';
import { useFocusEffect, useNavigation } from '@react-navigation/native';

import { FirebaseFirestoreTypes } from '@react-native-firebase/firestore';

Expand Down Expand Up @@ -31,9 +31,11 @@ const MyPets = (): JSX.Element => {
const user = userAPI.currentUserDocument();
const navigation = useNavigation();

useLayoutEffect(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimaryDark, false);
}, [navigation]);
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimaryDark, true);
}, []),
);

const animalKey = (animalItem: Animal): string => animalItem.id;

Expand Down Expand Up @@ -115,10 +117,11 @@ const MyPets = (): JSX.Element => {
}}
leftAction={{
hidden: false,
actionType: 'back',
actionType: 'drawer',
}}
rightAction={{
hidden: true,
hidden: false,
actionType: 'search',
}}
>
<Container>
Expand Down
18 changes: 12 additions & 6 deletions src/pages/Animal/Registration/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
// Package imports.
import React, { useLayoutEffect, useState } from 'react';
import React, { useCallback, useState } from 'react';
import { setStatusBarBackgroundColor } from 'expo-status-bar';
import { v4 as uuidv4 } from 'uuid';

import RadioForm from 'react-native-simple-radio-button';
import CheckBox from '@react-native-community/checkbox';
import { StackActions, useNavigation } from '@react-navigation/native';
import {
StackActions,
useFocusEffect,
useNavigation,
} from '@react-navigation/native';
import { Formik } from 'formik';
import * as Yup from 'yup';

Expand Down Expand Up @@ -61,10 +65,12 @@ export default function AnimalRegistration() : JSX.Element {
message: '',
});

// Layout effects.
useLayoutEffect(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarSecondaryDark, true);
}, [navigation]);
// Page effects.
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarSecondaryDark, true);
}, []),
);

// Styled components.
const {
Expand Down
12 changes: 7 additions & 5 deletions src/pages/Animal/Success/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useLayoutEffect } from 'react';
import React, { useCallback } from 'react';
import { setStatusBarBackgroundColor } from 'expo-status-bar';
import { useNavigation } from '@react-navigation/native';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import AsyncButton from '../../../components/AsyncButton';
import {
Container, Title, Message, ButtonContainer, ButtonText, styles,
Expand All @@ -11,9 +11,11 @@ import { Theme } from '../../../constants';
export default function AnimalRegistrationSuccess() : JSX.Element {
const navigation = useNavigation();

useLayoutEffect(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarSecondaryDark, false);
}, [navigation]);
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarSecondaryDark, true);
}, []),
);

return (
<HeaderLayout
Expand Down
12 changes: 7 additions & 5 deletions src/pages/Home/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useLayoutEffect } from 'react';
import React, { useCallback } from 'react';

import { useNavigation } from '@react-navigation/native';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import { setStatusBarBackgroundColor } from 'expo-status-bar';

import HeaderLayout from '../../layouts/HeaderLayout';
Expand All @@ -12,9 +12,11 @@ import { Images, Theme } from '../../constants';
export default function Home() : JSX.Element {
const navigation = useNavigation();

useLayoutEffect(() => {
setStatusBarBackgroundColor('transparent', true);
}, [navigation]);
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor('transparent', true);
}, []),
);

const {
Center, Container, Title, Message, ButtonText, LoginText, LogoContainer,
Expand Down
18 changes: 12 additions & 6 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// Package imports.
import React, { useLayoutEffect, useState } from 'react';
import React, { useCallback, useState } from 'react';

import { setStatusBarBackgroundColor } from 'expo-status-bar';
import { StackActions, useNavigation } from '@react-navigation/native';
import {
StackActions,
useFocusEffect,
useNavigation,
} from '@react-navigation/native';

import * as Yup from 'yup';
import { Formik } from 'formik';
Expand Down Expand Up @@ -49,10 +53,12 @@ export default function Login() : JSX.Element {
message: '',
});

// Layout effects.
useLayoutEffect(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimary, true);
}, [navigation]);
// Page effects.
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimary, true);
}, []),
);

const signIn = async ({ email, password }: LoginForm): Promise<void> => {
try {
Expand Down
15 changes: 8 additions & 7 deletions src/pages/NotificationsList/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Package imports.
import React, { useEffect, useLayoutEffect, useState } from 'react';
import React, { useCallback, useEffect, useState } from 'react';
import { setStatusBarBackgroundColor } from 'expo-status-bar';
import { Text, View } from 'react-native';
import { useNavigation } from '@react-navigation/native';
import { useFocusEffect, useNavigation } from '@react-navigation/native';
import { TouchableOpacity } from 'react-native-gesture-handler';
import MaterialIcons from 'react-native-vector-icons/MaterialIcons';
import { Theme } from '../../constants';
Expand All @@ -21,7 +21,6 @@ import notificationAPI, { NotificationType, NotificationModels } from '../../ser
export default function NotificationsList() : JSX.Element {
// Variables.
const navigation = useNavigation();
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const [fetchedNotifications, setFetchedNotifications] = useState<NotificationModels[]>([]);
const [fetchedOnce, setFetchedOnce] = useState(false);

Expand All @@ -35,12 +34,14 @@ export default function NotificationsList() : JSX.Element {
});
};

// Page effects.
useEffect(() => fetchNotifications(), []);

// Page effects.
useLayoutEffect(() => {
setStatusBarBackgroundColor('transparent', true);
}, [navigation]);
useFocusEffect(
useCallback(() => {
setStatusBarBackgroundColor(Theme.elements.statusBarPrimaryDark, true);
}, []),
);

const notificationRenderer = (notification: (NotificationModels)): JSX.Element => {
switch (notification.type) {
Expand Down
Loading