-
Notifications
You must be signed in to change notification settings - Fork 957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Configurable animations #837
Comments
No, we don't support configurable animations currently (even on the internal level), but it is on the plan for future releases. Let's keep this issue open to view the user interest and tracking a progress |
OK thanks - yes, i'll leave it open |
I think this should be out of scope for UI Kitten, there's some powerful and simple libraries like react-native-animatable that can be easily integrated with this library 🤔 |
@lesmo I guess there are some basic use-cases like animating modals that should be possible to customize, but currently there is no way to do that :) |
Yes! I'm very interested in having animated modals / popups / tooltips!! |
I'm going to look into the Animatable library though, I haven't seen that. |
@lesmo it's not about the difficulty to implement it or not - according to me the purpose of using a framework for your UI is to avoid this and to preserve consistancy and homogeneity of UI and UX |
i'd love to animated the TabView component as the easing / animation is too slow in my opinion |
In the meantime, anyone have any examples of an animated Modal they could share? Thanks! |
For modals, wrap your content in an Animated.View as first child. To start/stop animations on mount/unmount, you may create a wrapper class component where you can start and stop animations.
For other components, you can usually wrap them in Animated.View that you can then animate as you want.
Hopefully you'll find this useful :) |
Here's one way to animate a button using composition pattern: const AnimatedButton = ({ style, onPressIn, onPressOut, ...props }) => {
const animation = useRef(new Animated.Value(1)).current;
const handlePressIn = e => {
Animated.spring(animation, {
toValue: 0.5,
useNativeDriver: true,
}).start();
onPressIn && onPressIn(e);
};
const handlePressOut = e => {
Animated.spring(animation, {
toValue: 1,
friction: 3,
tension: 40,
useNativeDriver: true,
}).start();
onPressOut && onPressOut(e);
};
const animatedStyle = { transform: [{ scale: animation }] };
return (
<Button
onPressIn={handlePressIn}
onPressOut={handlePressOut}
{...props}
style={[style, animatedStyle]}
/>
);
}; |
If you wanted the Material ripple effect, you could use the const AnimatedButton = ({children, ...props}) => {
const theme = useTheme();
return (
<Ripple
rippleColor="white"
rippleOpacity={1}
style={{backgroundColor: theme['color-primary-default'], height: 60}}
{...props}>
<Text>{children}</Text>
</Ripple>
);
}; |
Follow up on my button example. If you want to animate styles like import React, { FC } from 'react';
import { Animated } from 'react-native';
import { Button, ButtonProps } from '@ui-kitten/components';
import { useScaleAnimation } from './useScaleAnimation';
const AnimatableButton = Animated.createAnimatedComponent(Button);
export const AnimatedButton: FC<ButtonProps> = (props) => {
const animatedProps = useScaleAnimation(props);
return <AnimatableButton {...animatedProps} />;
};
/*
If you need animation to be theme-able, you could add
an "AnimatedButton" key to custom mapping with
custom parameters that control animation type, then access
those parameters from eva prop by wrapping this component with the
styled HOC like this: styled('AnimatedButton')(AnimatedButton)
*/ import { useRef } from 'react';
import { Animated, Easing, GestureResponderEvent } from 'react-native';
import { ButtonProps, useTheme } from '@ui-kitten/components';
const BUTTON_PRESSED_SIZE = 0.95;
const BUTTON_EASING = Easing.bezier(0.25, 0.1, 0.25, 1);
export function useScaleAnimation({
appearance = 'filled',
status = 'primary',
onPressIn,
onPressOut,
style,
...props
}: ButtonProps): ButtonProps {
const scale = useRef(new Animated.Value(1)).current;
const theme = useTheme();
const shrink = () => {
Animated.timing(scale, {
toValue: BUTTON_PRESSED_SIZE,
duration: 100,
easing: BUTTON_EASING,
useNativeDriver: false,
}).start();
};
const grow = () => {
Animated.timing(scale, {
toValue: 1,
duration: 300,
easing: BUTTON_EASING,
useNativeDriver: false,
}).start();
};
const handlePressIn = (e: GestureResponderEvent) => {
shrink();
onPressIn && onPressIn(e);
};
const handlePressOut = (e: GestureResponderEvent) => {
grow();
onPressOut && onPressOut(e);
};
const animatedStyle: any = { transform: [{ scale }] };
if (appearance === 'filled') {
const defaultColor = theme[`color-${status}-default`];
const activeColor = theme[`color-${status}-active`];
const backgroundColor = scale.interpolate({
inputRange: [BUTTON_PRESSED_SIZE, 1],
outputRange: [activeColor, defaultColor],
});
animatedStyle.backgroundColor = backgroundColor;
}
return {
status,
appearance,
...props,
onPressIn: handlePressIn,
onPressOut: handlePressOut,
style: [style, animatedStyle],
};
} |
Another use case for this is to be able to control the animation ease curve when switching between Tabs in a TabView. I'd like to have some control of the speed an arrival ease as they feel quite abrupt. |
Hi
I would like to have a way to configure animation using ui.kitten.
For exemple when opening modal, select or menu etc.
Is there a way to do it properly? (using the theme for exemple, to preserve consistancy accross all the app)?
Thanks!
The text was updated successfully, but these errors were encountered: