Refactor some generic components

This commit is contained in:
Lei Nelissen
2020-06-21 10:30:41 +02:00
parent b04026b846
commit 38fa01620d
15 changed files with 153 additions and 90 deletions

View File

@@ -4,7 +4,7 @@ import TrackPlayer from 'react-native-track-player';
import { PersistGate } from 'redux-persist/integration/react';
import { NavigationContainer } from '@react-navigation/native';
import Routes from '../screens';
import store, { persistedStore } from '../store';
import store, { persistedStore } from 'store';
interface State {
isReady: boolean;

View File

@@ -0,0 +1,25 @@
import React, { useCallback } from 'react';
import { TouchableOpacity } from 'react-native';
interface TouchableHandlerProps {
id: string;
onPress: (id: string) => void;
}
/**
* This is a generic handler that accepts id as a prop, and return it when it is
* pressed. This comes in handy with lists in which albums / tracks need to be selected.
*/
const TouchableHandler: React.FC<TouchableHandlerProps> = ({ id, onPress, children }) => {
const handlePress = useCallback(() => {
return onPress(id);
}, [id]);
return (
<TouchableOpacity onPress={handlePress}>
{children}
</TouchableOpacity>
);
};
export default TouchableHandler;