Skip to content

Instantly share code, notes, and snippets.

View HussainArif12's full-sized avatar
🏠
Working from home

Hussain Arif HussainArif12

🏠
Working from home
View GitHub Profile
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");
}
const got = require("got");
async function getBuffer(url) {
const response = await got(url).buffer();
return response;
}
module.exports = getBuffer;
const sharp = require("sharp");
function createImage() {
sharp({
create: {
width: 100,
height: 200,
channels: 4,
background: { r: 100, g: 80, b: 100, alpha: 1 },
},
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} />
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,
//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"
/>
import { useRef } from "react";
import { Button } from "react-native";
const carouselRef = useRef(null);
return (
<View style={styles.container}>
<Carousel
ref={carouselRef}
/*further code... */
/>
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,
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>
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>
);