import * as React from 'react';
import { Text, View, StyleSheet, Image, Button, Platform } from 'react-native';
import { addMultipleGifs, deleteAllGifs, getSingleGif } from './GifManagement';
// those are Giphy.com ID's - they are hardcoded here,
// but if you have Giphy API key - you can use findGifs() from gifFetching.ts
const gifIds = ['YsTs5ltWtEhnq', 'cZ7rmKfFYOvYI', '11BCDu2iUc8Nvhryl7'];
function AppMain() {
//download all gifs at startup
React.useEffect(() => {
(async () => {
await addMultipleGifs(gifIds);
})();
//and unload at the end
return () => {
deleteAllGifs();
};
}, []);
//file uri of selected gif
const [selectedUri, setUri] = React.useState(null);
const handleSelect = async id => {
try {
setUri(await getSingleGif(id));
} catch (e) {
console.error("Couldn't load gif", e);
}
};
const unloadAll = () => {
setUri(null);
deleteAllGifs();
};
return (
See contents of gifManagement.ts
Select one of the IDs
{gifIds.map((item, index) => (
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 20,
justifyContent: 'center',
backgroundColor: '#ecf0f1',
padding: 8,
},
header: {
margin: 24,
fontSize: 18,
fontWeight: 'bold',
textAlign: 'center',
},
paragraph: {
textAlign: 'center',
marginBottom: 15,
},
});
function UnsupportedPlatform() {
return (
FileSystem doesn't support web. Run this on Android or iOS
);
}
export default function App() {
return Platform.OS === 'android' || Platform.OS === 'ios' ? : ;
}