// App.js
import React, { useState } from 'react';
import { View, Image, Text, Button, StyleSheet, ScrollView } from 'react-native';

const images = [
    { id: '1', src: require('./assets/photo1.jpg') },
    { id: '2', src: require('./assets/photo2.jpg') },
    { id: '3', src: require('./assets/photo3.jpg') },
];

const App = () => {
    const [currentImage, setCurrentImage] = useState(images[0]);

    const nextImage = () => {
        const currentIndex = images.findIndex(img => img.id === currentImage.id);
        const nextIndex = (currentIndex + 1) % images.length;
        setCurrentImage(images[nextIndex]);
    };

    const prevImage = () => {
        const currentIndex = images.findIndex(img => img.id === currentImage.id);
        const prevIndex = (currentIndex - 1 + images.length) % images.length;
        setCurrentImage(images[prevIndex]);
    };

    return (
        <View style={styles.container}>
            <Text style={styles.header}>Photo Browser</Text>
            <ScrollView style={styles.imageContainer}>
                <Image source={currentImage.src} style={styles.image} />
            </ScrollView>
            <View style={styles.buttonContainer}>
                <Button title="Previous" onPress={prevImage} />
                <Button title="Next" onPress={nextImage} />
            </View>
        </View>
    );
};

const styles = StyleSheet.create({
    container: {
        flex: 1,
        justifyContent: 'center',
        alignItems: 'center',
        backgroundColor: '#fff',
    },
    header: {
        fontSize: 24,
        marginBottom: 20,
    },
    imageContainer: {
        width: '100%',
        height: '70%',
    },
    image: {
        width: '100%',
        height: '100%',
        resizeMode: 'contain',
    },
    buttonContainer: {
        flexDirection: 'row',
        justifyContent: 'space-around',
        width: '100%',
        paddingHorizontal: 20,
    },
});

export default App;
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.