This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const getBuffer = require("./fetchUtils.js"); | |
const sharp = require("sharp"); | |
async function getImage() { | |
const unsplashBuffer = await getBuffer( | |
"https://images.unsplash.com/photo-1635074921144-a78163c43f35?ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&ixlib=rb-1.2.1&auto=format&fit=crop&w=924&q=80" | |
); | |
sharp(unsplashBuffer).jpeg().toFile("./output.jpg"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const got = require("got"); | |
async function getBuffer(url) { | |
const response = await got(url).buffer(); | |
return response; | |
} | |
module.exports = getBuffer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sharp = require("sharp"); | |
function createImage() { | |
sharp({ | |
create: { | |
width: 100, | |
height: 200, | |
channels: 4, | |
background: { r: 100, g: 80, b: 100, alpha: 1 }, | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import CustomPaging from "./CustomPaging"; | |
//extra code removed for brevity | |
const [slideIndex, setSlideIndex] = useState(0); | |
const settings = { | |
onSnapToItem: (index) => setSlideIndex(index), //add this in 'settings' variable. | |
}; | |
return ( | |
<View style={styles.container}> | |
<Carousel ref={carouselRef} {...settings} /> | |
<CustomPaging data={data} activeSlide={slideIndex} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { Pagination } from 'react-native-snap-carousel'; | |
import styles from './styles'; | |
export default function CustomPaging({ data, activeSlide }) { | |
const settings = { | |
dotsLength: data.length, | |
activeDotIndex: activeSlide, | |
containerStyle: styles.dotContainer, | |
dotStyle: styles.dotStyle, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code to add in 'return block' in CustomSlider.js | |
<View> | |
<Button | |
onPress={() => carouselRef.current.snapToItem(0)} | |
title="Go to start" | |
/> | |
<Button | |
onPress={() => carouselRef.current.snapToItem(data.length - 1)} | |
title="Go to end" | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useRef } from "react"; | |
import { Button } from "react-native"; | |
const carouselRef = useRef(null); | |
return ( | |
<View style={styles.container}> | |
<Carousel | |
ref={carouselRef} | |
/*further code... */ | |
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Dimensions } from "react-native"; | |
import Carousel from "react-native-snap-carousel"; | |
import CarouselItem from "./CarouselItem"; | |
import styles from "./styles"; | |
const { width } = Dimensions.get("window"); | |
export default function CustomSlider({ data }) { | |
const settings = { | |
sliderWidth: width, | |
sliderHeight: width, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { View } from 'react-native'; | |
import data from './data'; | |
import CustomSlider from './CustomSlider'; | |
// You can import from local files | |
// or any pure javascript modules available in npm | |
export default function App() { | |
return ( | |
<View> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as React from 'react'; | |
import { View, Text } from 'react-native'; | |
export default function CustomSlider({ data }) { | |
console.log(data); | |
return ( | |
<View> | |
<Text> Hello, world</Text> | |
</View> | |
); |