Skip to content

Commit

Permalink
chore: update example with onVerticalPull background animation
Browse files Browse the repository at this point in the history
  • Loading branch information
Glazzes committed Aug 2, 2024
1 parent 7533ec1 commit 17db2e1
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 22 deletions.
8 changes: 2 additions & 6 deletions example/app.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
"resizeMode": "contain",
"backgroundColor": "#ffffff"
},
"assetBundlePatterns": [
"**/*"
],
"assetBundlePatterns": ["**/*"],
"ios": {
"supportsTablet": true,
"bundleIdentifier": "com.glazzes.example"
Expand All @@ -30,8 +28,6 @@
"favicon": "./assets/favicon.png",
"bundler": "metro"
},
"plugins": [
"expo-router"
]
"plugins": ["expo-router"]
}
}
49 changes: 37 additions & 12 deletions example/src/gallery/GalleryExample.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import React, { useCallback, useEffect, useRef, useState } from 'react';
import { View } from 'react-native';
import { useSharedValue, withTiming } from 'react-native-reanimated';
import {
stackTransition,
Gallery,
type GalleryType,
} from 'react-native-zoom-toolkit';
import { StyleSheet } from 'react-native';
import Animated, {
interpolateColor,
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
import {
getAssetsAsync,
MediaType,
requestPermissionsAsync,
MediaType,
type Asset,
} from 'expo-media-library';
import {
stackTransition,
Gallery,
PinchCenteringMode,
type GalleryType,
} from 'react-native-zoom-toolkit';

import GalleryImage from './GalleryImage';
import { StyleSheet } from 'react-native';
import VideoControls from './controls/VideoControls';
import GalleryVideo from './GalleryVideo';

Expand Down Expand Up @@ -67,6 +72,25 @@ const GalleryExample = () => {
opacityControls.value = withTiming(toValue);
}, [assets, activeIndex, opacityControls]);

// used to derived the color animation when pulling vertically
const translateY = useSharedValue<number>(0);
const onVerticalPulling = (ty: number) => {
'worklet';
translateY.value = ty;
};

const animatedStyle = useAnimatedStyle(() => {
const color = interpolateColor(
translateY.value,
[-150, 0, 150],
['#fff', '#000', '#fff'],
'RGB',
{ gamma: 2.2 }
);

return { backgroundColor: color };
});

useEffect(() => {
const requestAssets = async () => {
const { granted } = await requestPermissionsAsync();
Expand Down Expand Up @@ -95,7 +119,7 @@ const GalleryExample = () => {
}

return (
<View style={styles.root}>
<Animated.View style={[styles.root, animatedStyle]}>
<Gallery
ref={ref}
data={assets}
Expand All @@ -106,6 +130,8 @@ const GalleryExample = () => {
activeIndex.value = idx;
}}
onTap={onTap}
pinchCenteringMode={PinchCenteringMode.INTERACTION}
onVerticalPull={onVerticalPulling}
customTransition={customTransition}
/>

Expand All @@ -116,14 +142,13 @@ const GalleryExample = () => {
isSeeking={isSeeking}
opacity={opacityControls}
/>
</View>
</Animated.View>
);
};

const styles = StyleSheet.create({
root: {
flex: 1,
backgroundColor: '#000',
},
});

Expand Down
2 changes: 1 addition & 1 deletion example/src/gallery/GalleryImage.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useState } from 'react';
import { useWindowDimensions } from 'react-native';
import { Image } from 'expo-image';
import {
runOnJS,
useAnimatedReaction,
type SharedValue,
} from 'react-native-reanimated';
import { Image } from 'expo-image';
import { type Asset } from 'expo-media-library';

import { calculateItemSize } from './utils/utils';
Expand Down
2 changes: 1 addition & 1 deletion example/src/gallery/GalleryVideo.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useEffect, useRef } from 'react';
import { useWindowDimensions } from 'react-native';
import { type SharedValue } from 'react-native-reanimated';
import { ResizeMode, Video, type AVPlaybackStatus } from 'expo-av';
import type { Asset } from 'expo-media-library';

Expand All @@ -10,7 +11,6 @@ import {
listenToSeekVideoEvent,
listenToStopVideoEvent,
} from './utils/emitter';
import { type SharedValue } from 'react-native-reanimated';

type GalleryVideoProps = {
asset: Asset;
Expand Down
4 changes: 2 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ pre-commit:
parallel: true
commands:
lint:
glob: "*.{js,ts,jsx,tsx}"
glob: '*.{js,ts,jsx,tsx}'
run: yarn eslint {staged_files}
types:
glob: "*.{js,ts, jsx, tsx}"
glob: '*.{js,ts, jsx, tsx}'
run: npx tsc --noEmit
commit-msg:
parallel: true
Expand Down

0 comments on commit 17db2e1

Please sign in to comment.