Skip to content

Commit

Permalink
Merge pull request #2812 from ecency/nt/rever-reanimated-with-fix
Browse files Browse the repository at this point in the history
Nt/rever reanimated with fix
  • Loading branch information
feruzm authored Jan 18, 2024
2 parents 5c96519 + d7faf0a commit 84ba304
Show file tree
Hide file tree
Showing 12 changed files with 434 additions and 305 deletions.
202 changes: 109 additions & 93 deletions ios/Ecency.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

20 changes: 11 additions & 9 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,12 @@ PODS:
- React-Core
- react-native-restart (0.0.24):
- React-Core
- react-native-safe-area-context (4.8.1):
- react-native-safe-area-context (4.5.0):
- RCT-Folly
- RCTRequired
- RCTTypeSafety
- React-Core
- ReactCommon/turbomodule/core
- react-native-udp (4.1.7):
- CocoaAsyncSocket
- React-Core
Expand Down Expand Up @@ -619,12 +623,11 @@ PODS:
- React
- RNPermissions (3.7.3):
- React-Core
- RNReanimated (3.6.1):
- RNReanimated (2.14.4):
- DoubleConversion
- FBLazyVector
- FBReactNativeSpec
- glog
- hermes-engine
- RCT-Folly
- RCTRequired
- RCTTypeSafety
Expand All @@ -634,7 +637,6 @@ PODS:
- React-Core/RCTWebSocket
- React-CoreModules
- React-cxxreact
- React-hermes
- React-jsi
- React-jsiexecutor
- React-jsinspector
Expand All @@ -648,7 +650,7 @@ PODS:
- React-RCTText
- ReactCommon/turbomodule/core
- Yoga
- RNScreens (3.29.0):
- RNScreens (3.14.0):
- React-Core
- React-RCTImage
- RNSVG (12.5.1):
Expand Down Expand Up @@ -1055,7 +1057,7 @@ SPEC CHECKSUMS:
React: ec6efc54c0fbb7c2e7147624c78065be80753082
React-bridging: 7dd96a58f896a1a7422a491d17ec644e87277953
React-callinvoker: f348d204f7bbe6020d4fd0dd57303f5b48a28003
React-Codegen: 4d4cbbc69c4c934243dd61147f65b987259a1358
React-Codegen: 73350192a09163a640c23baf795464474be0d793
React-Core: c57b11fd672421049038ef36881372da2605a0cd
React-CoreModules: 2d91acffc3924adac6b508e3fc44121aa719ec40
React-cxxreact: ee2ab13a1db086dc152421aa42dc94cc68f412a1
Expand All @@ -1080,7 +1082,7 @@ SPEC CHECKSUMS:
react-native-receive-sharing-intent: 62ab28c50e6ae56d32b9e841d7452091312a0bc7
react-native-render-html: 984dfe2294163d04bf5fe25d7c9f122e60e05ebe
react-native-restart: 45c8dca02491980f2958595333cbccd6877cb57e
react-native-safe-area-context: cd1169d797a2ef722a00bfc5af10748d5b6c94f9
react-native-safe-area-context: 39c2d8be3328df5d437ac1700f4f3a4f75716acc
react-native-udp: df79c3cb72c4e71240cd3ce4687bfb8a137140d5
react-native-version-number: b415bbec6a13f2df62bf978e85bc0d699462f37f
react-native-video: c26780b224543c62d5e1b2a7244a5cd1b50e8253
Expand Down Expand Up @@ -1115,8 +1117,8 @@ SPEC CHECKSUMS:
RNNotifee: 053c0ace9c73634709a0214fd9c436a5777a562f
RNOS: 6f2f9a70895bbbfbdad7196abd952e7b01d45027
RNPermissions: 314155ed6ce65237e7bd9fb6239219cce83228d3
RNReanimated: c5a0074efffd21f4af324e86b19468758fe39fa2
RNScreens: fa9b582d85ae5d62c91c66003b5278458fed7aaa
RNReanimated: 6668b0587bebd4b15dd849b99e5a9c70fc12ed95
RNScreens: 4830eb40e0793b38849965cd27f4f3a7d7bc65c1
RNSVG: d7d7bc8229af3842c9cfc3a723c815a52cdd1105
RNTusClient: b90393226531c118c4716a2b71128e3b9d9c77ee
RNVectorIcons: 368d6d8b8301224e5ffb6254191f4f8876c2be0d
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@
"react-native-qrcode-scanner": "^1.5.5",
"react-native-qrcode-svg": "^6.0.3",
"react-native-randombytes": "^3.6.1",
"react-native-reanimated": "^3.6.1",
"react-native-reanimated": "^2.12.0",
"react-native-receive-sharing-intent": "^2.0.0",
"react-native-render-html": "^6.0.5",
"react-native-restart": "^0.0.24",
"react-native-safe-area-context": "^4.8.1",
"react-native-screens": "^3.29.0",
"react-native-safe-area-context": "^4.4.1",
"react-native-screens": "3.14.0",
"react-native-scrollable-tab-view": "ecency/react-native-scrollable-tab-view",
"react-native-select-dropdown": "^3.4.0",
"react-native-slider": "^0.11.0",
Expand Down
13 changes: 0 additions & 13 deletions patches/react-native+0.70.7.patch
Original file line number Diff line number Diff line change
Expand Up @@ -70,19 +70,6 @@ index 0000000..361f5fb
+++ b/node_modules/react-native/scripts/.packager.env
@@ -0,0 +1 @@
+export RCT_METRO_PORT=8081
diff --git a/node_modules/react-native/scripts/cocoapods/codegen_utils.rb b/node_modules/react-native/scripts/cocoapods/codegen_utils.rb
index 406e993..2c64fa5 100644
--- a/node_modules/react-native/scripts/cocoapods/codegen_utils.rb
+++ b/node_modules/react-native/scripts/cocoapods/codegen_utils.rb
@@ -84,7 +84,7 @@ class CodegenUtils
'source' => { :git => '' },
'header_mappings_dir' => './',
'platforms' => {
- 'ios' => '11.0',
+ 'ios' => '12.0',
},
'source_files' => "**/*.{h,mm,cpp}",
'pod_target_xcconfig' => { "HEADER_SEARCH_PATHS" =>
diff --git a/node_modules/react-native/sdks/hermes/hermes-engine.podspec b/node_modules/react-native/sdks/hermes/hermes-engine.podspec
new file mode 100644
index 0000000..8d331e0
Expand Down
129 changes: 72 additions & 57 deletions src/components/markdownEditor/children/editorToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
import React, { useEffect, useRef, useState } from 'react';
import { Keyboard, View, ViewStyle } from 'react-native';
import React, { useEffect, useMemo, useRef, useState } from 'react';
import {
FlatList,
Gesture,
GestureDetector,
GestureStateChangeEvent,
HandlerStateChangeEvent,
PanGestureHandler,
PanGestureHandlerEventPayload,
} from 'react-native-gesture-handler';
import { getBottomSpace } from 'react-native-iphone-x-helper';
import Animated, {
Easing,
clamp,
runOnJS,
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
import Animated, { EasingNode, Extrapolate } from 'react-native-reanimated';
import { IconButton, UploadsGalleryModal } from '../..';
import styles from '../styles/editorToolbarStyles';
import { useAppSelector } from '../../../hooks';
import { MediaInsertData, Modes } from '../../uploadsGalleryModal/container/uploadsGalleryModal';
import styles from '../styles/editorToolbarStyles';
import Formats from './formats/formats';

type Props = {
Expand Down Expand Up @@ -51,10 +43,10 @@ export const EditorToolbar = ({
}: Props) => {
const currentAccount = useAppSelector((state) => state.account.currentAccount);
const uploadsGalleryModalRef = useRef<typeof UploadsGalleryModal>(null);
const translateY = useRef(new Animated.Value(200));
const shouldHideExtension = useRef(false);
const extensionHeight = useRef(0);

const translateY = useSharedValue(200);

const [isExtensionVisible, setIsExtensionVisible] = useState(false);
const [isKeyboardVisible, setKeyboardVisible] = useState(false);

Expand Down Expand Up @@ -111,69 +103,92 @@ export const EditorToolbar = ({
_showUploadsExtension(Modes.MODE_VIDEO);
};

const _onPanEnd = (e: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => {
console.log('finalize', e.velocityY, e.translationY);
const _shouldHide = e.velocityY > 300 || e.translationY > extensionHeight.current / 2;
if (_shouldHide) {
_hideExtension();
} else {
_revealExtension();
}
};
// handles extension closing
const _onGestureEvent = Animated.event(
[
{
nativeEvent: {
translationY: translateY.current,
},
},
],
{
useNativeDriver: false,
},
);

const _gestureHandler = Gesture.Pan()
.onChange((e) => {
translateY.value = e.translationY;
})
.onFinalize((e) => {
runOnJS(_onPanEnd)(e);
});
const consY = useMemo(
() =>
translateY.current.interpolate({
inputRange: [0, 500],
outputRange: [0, 500],
extrapolate: Extrapolate.CLAMP,
}),
[translateY.current],
);

const _animatedStyle = useAnimatedStyle(() => {
// Clamp the interpolated value to a specific range
return {
transform: [{ translateY: clamp(translateY.value, 0, 500) }],
};
});
const _animatedStyle = {
transform: [
{
translateY: consY,
},
],
};

const _onPanHandlerStateChange = (e: HandlerStateChangeEvent<PanGestureHandlerEventPayload>) => {
console.log(
'handler state change',
e.nativeEvent.velocityY,
e.nativeEvent.velocityY > 300,
e.nativeEvent.translationY,
);
shouldHideExtension.current =
e.nativeEvent.velocityY > 300 || e.nativeEvent.translationY > extensionHeight.current / 2;
};

const _revealExtension = () => {
if (!isExtensionVisible) {
translateY.value = 200;
translateY.current.setValue(200);
}

setIsExtensionVisible(true);

translateY.value = withTiming(0, {
Animated.timing(translateY.current, {
duration: 200,
easing: Easing.inOut(Easing.ease),
});
toValue: 0,
easing: EasingNode.inOut(EasingNode.ease),
}).start();
};

const _hideExtension = () => {
const _onComplete = () => {
Animated.timing(translateY.current, {
toValue: extensionHeight.current,
duration: 200,
easing: EasingNode.inOut(EasingNode.ease),
}).start(() => {
shouldHideExtension.current = false;
setIsExtensionVisible(false);
if (uploadsGalleryModalRef.current) {
uploadsGalleryModalRef.current.toggleModal(false);
}
};
});
};

translateY.value = withTiming(
extensionHeight.current,
{
duration: 200,
easing: Easing.inOut(Easing.ease),
},
(success) => {
if (success) {
runOnJS(_onComplete)();
}
},
);
const _onPanEnded = () => {
if (shouldHideExtension.current) {
_hideExtension();
} else {
_revealExtension();
}
};

const _renderExtension = () => {
return (
<GestureDetector gesture={_gestureHandler}>
<PanGestureHandler
onGestureEvent={_onGestureEvent}
onHandlerStateChange={_onPanHandlerStateChange}
onEnded={_onPanEnded}
>
<Animated.View style={_animatedStyle}>
<View
onLayout={(e) => {
Expand All @@ -197,7 +212,7 @@ export const EditorToolbar = ({
/>
</View>
</Animated.View>
</GestureDetector>
</PanGestureHandler>
);
};

Expand Down
67 changes: 67 additions & 0 deletions src/components/progressiveImage/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React, { useState } from 'react';
import { View, StyleSheet } from 'react-native';
import FastImage from 'react-native-fast-image';
import Animated, { EasingNode } from 'react-native-reanimated';

const styles = StyleSheet.create({
imageOverlay: {
position: 'absolute',
left: 0,
right: 0,
bottom: 0,
top: 0,
borderRadius: 8,
},
container: {
backgroundColor: '#f6f6f6',
borderRadius: 8,
},
});

const AnimatedFastImage = Animated.createAnimatedComponent(FastImage);

const ProgressiveImage = ({ thumbnailSource, source, style, ...props }) => {
// const [calcImgHeight, setCalcImgHeight] = useState(300);
const thumbnailAnimated = new Animated.Value(0);
const imageAnimated = new Animated.Value(0);

const handleThumbnailLoad = (e) => {
/* if (e) {
setCalcImgHeight(Math.floor((e.nativeEvent.height / e.nativeEvent.width) * dim.width));
console.log(e.nativeEvent.width, e.nativeEvent.height);
} */
Animated.timing(thumbnailAnimated, {
toValue: 1,
easing: EasingNode.inOut(EasingNode.ease),
}).start();
};

const onImageLoad = () => {
Animated.timing(imageAnimated, {
toValue: 1,
easing: EasingNode.inOut(EasingNode.ease),
}).start();
};

return (
<View style={styles.container}>
<AnimatedFastImage
{...props}
source={thumbnailSource}
style={[style, { opacity: thumbnailAnimated }]}
onLoad={handleThumbnailLoad}
blurRadius={1}
resizeMode={FastImage.resizeMode.cover}
/>
<AnimatedFastImage
{...props}
source={source}
style={[styles.imageOverlay, { opacity: imageAnimated }, style]}
onLoad={onImageLoad}
resizeMode={FastImage.resizeMode.cover}
/>
</View>
);
};

export default ProgressiveImage;
6 changes: 2 additions & 4 deletions src/components/quickReplyModal/quickReplyModalView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useRef, useState } from 'react';
import ActionSheet from 'react-native-actions-sheet';
import Animated, { FadeIn, FadeOut } from 'react-native-reanimated';
import { View } from 'react-native';
import { QuickReplyModalContent } from './quickReplyModalContent';
import { useAppDispatch, useAppSelector } from '../../hooks';
import { hideReplyModal } from '../../redux/actions/uiAction';
Expand Down Expand Up @@ -50,9 +50,7 @@ const QuickReplyModal = () => {
onClose={_onClose}
/>
</ActionSheet>
{backdropVisible && (
<Animated.View exiting={FadeOut} entering={FadeIn} style={styles.backdrop} />
)}
{backdropVisible && <View style={styles.backdrop} />}
</>
);
};
Expand Down
Loading

0 comments on commit 84ba304

Please sign in to comment.