Comments (6)
Hey! π
The issue doesn't seem to contain a minimal reproduction.
Could you provide a snack or a link to a GitHub repository under your username that reproduces the problem?
from react-native-reanimated.
Hey @Michota would you be able to provide a minimal reproduction that contains the problem? Your example is quite complicated. Also, looking at the code I can tell at least one thing that is not completely fine: dislikeButtonOffset
won't be a reactive shared value, because you create it depending on other shared value. I'd suggest using useDerivedValue in such situation.
from react-native-reanimated.
Can you tell me why does this work? For some reason derivedValue as an object does not work, but it does work as two values.
const dislikeButtonOffset = useSharedValue({
x: dislikeButtonStartPosition.value.x,
y: dislikeButtonStartPosition.value.y,
});
const curtainOffset = useSharedValue(0);
const curtainWidth = useSharedValue(0);
const dislikeButtonOffsetX = useDerivedValue(() => dislikeButtonOffset.value.x);
const dislikeButtonOffsetY = useDerivedValue(() => dislikeButtonOffset.value.y);
const dislikeButtonSize = useSharedValue(DISLIKE_BUTTON_SIZE);
const dislikeButtonAnimatedStyles = useAnimatedStyle(() => {
return {
backgroundColor: "yellow",
position: "absolute",
justifyContent: "center",
alignItems: "center",
borderRadius: 100,
width: dislikeButtonSize.value,
height: dislikeButtonSize.value,
transform: [
{ translateX: dislikeButtonOffsetX.value },
{ translateY: dislikeButtonOffsetY.value },
But this does not?
const dislikeButtonOffset = useSharedValue({
x: dislikeButtonStartPosition.value.x,
y: dislikeButtonStartPosition.value.y,
});
const curtainOffset = useSharedValue(0);
const curtainWidth = useSharedValue(0);
const dislikeButtonOffsetTwo = useDerivedValue(() => dislikeButtonOffset.value);
const dislikeButtonSize = useSharedValue(DISLIKE_BUTTON_SIZE);
const dislikeButtonAnimatedStyles = useAnimatedStyle(() => {
return {
backgroundColor: "yellow",
position: "absolute",
justifyContent: "center",
alignItems: "center",
borderRadius: 100,
width: dislikeButtonSize.value,
height: dislikeButtonSize.value,
transform: [
{ translateX: dislikeButtonOffsetTwo.value.x },
{ translateY: dislikeButtonOffsetTwo.value.y },
from react-native-reanimated.
Btw. changing dislikeButtonOffset
to derived value will allow me to change its values in different functions, like this one?
Currently I am animating this in following way:
const curtainShrinkRight = useCallback(() => {
runOnUI(() => {
isDislikeButtonHidden.value = false;
dislikeButtonOffset.value = {
x: withTiming(dislikeButtonStartPosition.value.x, {
duration: 0,
}),
y: withTiming(dislikeButtonStartPosition.value.y, {
duration: 0,
}),
};
})();
curtainOffset.value = withTiming(0, {
duration: DISLIKE_CURTAIN_TIME.shrink,
});
curtainWidth.value = withTiming(0, {
duration: DISLIKE_CURTAIN_TIME.shrink,
});
}, [
curtainOffset,
curtainWidth,
dislikeButtonOffset,
isDislikeButtonHidden,
dislikeButtonStartPosition.value.x,
dislikeButtonStartPosition.value.y,
]);
// some skipped code...
useEffect(() => {
if (isExpanded === false) {
curtainShrinkRight();
}
}, [isExpanded, curtainShrinkRight]);
How do i modify it? Using modify()
does not work, maybe I dont understand something...
from react-native-reanimated.
May this be related to fact, that animations are being run in UI thread?
const curtainExpandRight = useCallback(() => {
curtainWidth.value = withTiming(screenDimensions.width / 2, {
duration: DISLIKE_CURTAIN_TIME.expand,
});
curtainOffset.value = withDelay(
DISLIKE_CURTAIN_TIME.expand,
withTiming(
0,
{
duration: DISLIKE_CURTAIN_TIME.expand,
},
() => {
runOnJS(onCurtainExpand)();
isDislikeButtonHidden.value = true;
}
)
);
}, [curtainOffset, curtainWidth, screenDimensions.width, onCurtainExpand, isDislikeButtonHidden]);
const curtainShrinkRight = useCallback(() => {
runOnUI(() => {
isDislikeButtonHidden.value = false;
dislikeButtonOffset.value = {
x: withTiming(dislikeButtonStartPosition.x, {
duration: 0,
}),
y: withTiming(dislikeButtonStartPosition.y, {
duration: 0,
}),
};
})();
from react-native-reanimated.
Hi @Michota. I ran your first code snippet in the following way:
import React from 'react';
import Animated, {
useSharedValue,
useAnimatedStyle,
withSpring,
} from 'react-native-reanimated';
const DISLIKE_BUTTON_START_POSITION = {x: 0, y: 0};
const windowDimensions = {height: 100};
const DISLIKE_BUTTON_SIZE = 100;
export default function App() {
const isDislikeButtonHidden = useSharedValue(false);
const dislikeButtonStartPosition = useSharedValue({
x: DISLIKE_BUTTON_START_POSITION.x,
y: windowDimensions.height - 100,
});
const dislikeButtonOffset = useSharedValue({
x: dislikeButtonStartPosition.value.x,
y: dislikeButtonStartPosition.value.y,
});
const dislikeButtonSize = useSharedValue(DISLIKE_BUTTON_SIZE);
console.log(dislikeButtonOffset.value.x, dislikeButtonOffset.value.y); // THERE THEY ARE LOGGED AS NUMBER
const dislikeButtonAnimatedStyles = useAnimatedStyle(() => {
console.log(dislikeButtonOffset.value.x, dislikeButtonOffset.value.y); // THERE THEY ARE LOGGED AS OBJECT
return {
backgroundColor: 'red',
position: 'absolute',
justifyContent: 'center',
alignItems: 'center',
borderRadius: 100,
width: dislikeButtonSize.value,
height: dislikeButtonSize.value,
transform: [
{translateX: dislikeButtonOffset.value.x},
{translateY: dislikeButtonOffset.value.y},
{scale: withSpring(isDislikeButtonHidden.value ? 0 : 1)},
],
};
});
return <Animated.View style={dislikeButtonAnimatedStyles} />;
}
And everything works fine. From what you posted it seems like you have misassigned an animation somewhere to a shared value. If you want us to help you, I'm afraid you'd need to submit a complete component code (or a reproducible example) instead of little bits of it.
from react-native-reanimated.
Related Issues (20)
- [Reanimated] Babel plugin exception: TypeError: (0 , types_12.cloneNode) is not a function HOT 1
- Unable to run on Android HOT 3
- ReferenceError: _updateDataSynchronously is not defined HOT 2
- [3.6.0] pod install error after upgrading 3.6.0 HOT 4
- Problems with react-native-reanimated v3.11.0 e react-native v 0.74.1 HOT 5
- Unable to resolve module ./publicGlobals HOT 4
- γBugγModal displays incorrectly if use reanimated HOT 7
- [3.11.0] Plugin does not traverse node_modules, only the root of the project HOT 2
- Flickering in animation after updating react native HOT 11
- 1st item in an inverted list is no longer animated after a while with itemLayoutAnimation HOT 1
- expo 51.0.7 CRASH [TypeError: animatedRef.getTag is not a function (it is undefined)] HOT 3
- useAnimatedKeyboard break navigation color HOT 5
- Found Error TypeScript when run yarn tsc HOT 2
- Task :react-native-reanimated:buildCMakeRelWithDebInfo[armeabi-v7a] FAILED HOT 4
- Entering and/or layout animation flickering when SafeAreaView is a first parent of an animated component HOT 1
- > java.net.SocketException: Connection reset HOT 1
- iOS build faied: ld: Undefined symbols HOT 3
- SVG Polygon Animation not working HOT 1
- [3.12.0] TypeError: property is not configurable on useAnimatedStyle hook HOT 9
- useSharedValue `modify` does not exist, but shows in docs HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-reanimated.