Skip to content
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

0.72 Animation not work correctly #38019

Closed
edstbbz opened this issue Jun 22, 2023 · 13 comments
Closed

0.72 Animation not work correctly #38019

edstbbz opened this issue Jun 22, 2023 · 13 comments
Labels
API: Animated Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Stale There has been a lack of activity on this issue and it may be closed soon.

Comments

@edstbbz
Copy link

edstbbz commented Jun 22, 2023

Description

After update to 0.72 animation does't work

React Native Version

0.72.0

Output of npx react-native info

System:
OS: macOS 12.6.1
CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 38.58 MB / 16.00 GB
Shell:
version: 5.8.1
path: /bin/zsh
Binaries:
Node:
version: 16.13.0
path: /usr/local/bin/node
Yarn:
version: 3.2.1
path: /usr/local/bin/yarn
npm:
version: 8.1.0
path: /usr/local/bin/npm
Watchman:
version: 2022.10.24.00
path: /usr/local/bin/watchman
Managers:
CocoaPods: Not Found
SDKs:
iOS SDK:
Platforms:

  • DriverKit 21.4
  • iOS 16.0
  • macOS 12.3
  • tvOS 16.0
  • watchOS 9.0
    Android SDK: Not Found
    IDEs:
    Android Studio: 2022.1 AI-221.6008.13.2211.9514443
    Xcode:
    version: 14.0.1/14A400
    path: /usr/bin/xcodebuild
    Languages:
    Java:
    version: 11.0.11
    path: /usr/bin/javac
    Ruby:
    version: 2.6.5
    path: /Users/user/.rvm/rubies/ruby-2.6.5/bin/ruby
    npmPackages:
    "@react-native-community/cli": Not Found
    react:
    installed: 18.2.0
    wanted: 18.2.0
    react-native:
    installed: 0.72.0
    wanted: 0.72.0
    react-native-macos: Not Found
    npmGlobalPackages:
    "react-native": Not Found
    Android:
    hermesEnabled: true
    newArchEnabled: false
    iOS:
    hermesEnabled: false
    newArchEnabled: false

Steps to reproduce

const Searchbar = (
{
onChange,
onInputShow = noop,
onHide,
onShow,
iconStyle,
showOnMount = false,
showOnQuery,
withDebounce = true,
debounceTime = 200,
placeholder = 'Поиск',
closeButtonText = 'Отмена',
keyboardType = null,
multiline = false,
},
ref
) => {
const [value, setValue] = useState(null);
const [isShowInput, hideInput, showInput] = useToggleState(false);
const [keyboardTypeValue, setKeyboardTypeValue] = useState(keyboardType);
const [mount, setMount] = useState(false);

const scale = useRef(new Animated.Value(1)).current;

const inputRef = useRef(null);

const debouncedChange = useCallback(debounce(onChange, debounceTime), [onChange]);

useEffect(() => {
showOnMount && showSearchInput();
}, []);

useEffect(() => {
setKeyboardTypeValue(keyboardType);
}, [keyboardType]);

useEffect(() => {
!!showOnQuery && mount && showSearchInputOnQuery();
if (!mount) {
setMount(true);
}
}, [showOnQuery]);

useEffect(() => {
searchOnChange();
}, [value]);

const searchOnChange = () => {
if (value !== null) {
if (withDebounce) {
debouncedChange(value);
} else {
onChange(value);
}
}
};

const handleChange = searchValue => setValue(searchValue);

const runAnimate = (to = 1, start = false) => {
Animated.timing(scale, {
toValue: to,
duration: 200,
useNativeDriver: true,
}).start(() => start && inputRef.current?.focus());
};

const showSearchInput = () => {
onInputShow();
!!onShow && onShow();
showInput();
runAnimate(0, true);
};

const showSearchInputOnQuery = () => {
!!onShow && onShow();
showInput();
runAnimate(0, false);
};

const hideSearchInput = () => {
inputRef.current?.blur();
setValue(null);
!!onHide && onHide();
Animated.timing(scale, {
toValue: 1,
duration: 150,
useNativeDriver: true,
}).start(hideInput);
};

const inputAnimation = scale.interpolate({
inputRange: [0, 1],
outputRange: [1, 0],
});

useImperativeHandle(ref, () => ({
focus: () => inputRef.current.focus(),
serachBarShowed: isShowInput,
}));

return (
<>
{!isShowInput && (
<Animated.View style={[styles.searchIcon, { transform: [{ scale }] }, iconStyle]}>

</Animated.View>
)}
{isShowInput && (
<Animated.View
style={[styles.searchView, { transform: [{ scaleY: inputAnimation }] }, { opacity: inputAnimation }]}
>

<View style={{ flex: 0.8 }}>


<View style={{ flex: 0.25, alignItems: 'center' }}>



</Animated.View>
)}
</>
);
};

const styles = StyleSheet.create({
searchView: {
position: 'absolute',
left: 0,
right: 0,
backgroundColor: 'white',
paddingTop: 6,
paddingBottom: 8,
paddingLeft: 10,
paddingRight: 0,
zIndex: 3,
},
searchIcon: {
flex: 1,
position: 'absolute',
right: 20,
top: 13,
overflow: 'hidden',
zIndex: 3,
},
searchContainer: {
flex: 1,
flexDirection: 'row',
},
});

export default forwardRef(Searchbar); - dont work animation, Fixed only by creating a separate animation value for each element

Snack, code example, screenshot, or link to a repository

const Searchbar = (
{
onChange,
onInputShow = noop,
onHide,
onShow,
iconStyle,
showOnMount = false,
showOnQuery,
withDebounce = true,
debounceTime = 200,
placeholder = 'Поиск',
closeButtonText = 'Отмена',
keyboardType = null,
multiline = false,
},
ref
) => {
const [value, setValue] = useState(null);
const [isShowInput, hideInput, showInput] = useToggleState(false);
const [keyboardTypeValue, setKeyboardTypeValue] = useState(keyboardType);
const [mount, setMount] = useState(false);

const scale = useRef(new Animated.Value(1)).current;

const inputRef = useRef(null);

const debouncedChange = useCallback(debounce(onChange, debounceTime), [onChange]);

useEffect(() => {
showOnMount && showSearchInput();
}, []);

useEffect(() => {
setKeyboardTypeValue(keyboardType);
}, [keyboardType]);

useEffect(() => {
!!showOnQuery && mount && showSearchInputOnQuery();
if (!mount) {
setMount(true);
}
}, [showOnQuery]);

useEffect(() => {
searchOnChange();
}, [value]);

const searchOnChange = () => {
if (value !== null) {
if (withDebounce) {
debouncedChange(value);
} else {
onChange(value);
}
}
};

const handleChange = searchValue => setValue(searchValue);

const runAnimate = (to = 1, start = false) => {
Animated.timing(scale, {
toValue: to,
duration: 200,
useNativeDriver: true,
}).start(() => start && inputRef.current?.focus());
};

const showSearchInput = () => {
onInputShow();
!!onShow && onShow();
showInput();
runAnimate(0, true);
};

const showSearchInputOnQuery = () => {
!!onShow && onShow();
showInput();
runAnimate(0, false);
};

const hideSearchInput = () => {
inputRef.current?.blur();
setValue(null);
!!onHide && onHide();
Animated.timing(scale, {
toValue: 1,
duration: 150,
useNativeDriver: true,
}).start(hideInput);
};

const inputAnimation = scale.interpolate({
inputRange: [0, 1],
outputRange: [1, 0],
});

useImperativeHandle(ref, () => ({
focus: () => inputRef.current.focus(),
serachBarShowed: isShowInput,
}));

return (
<>
{!isShowInput && (
<Animated.View style={[styles.searchIcon, { transform: [{ scale }] }, iconStyle]}>

</Animated.View>
)}
{isShowInput && (
<Animated.View
style={[styles.searchView, { transform: [{ scaleY: inputAnimation }] }, { opacity: inputAnimation }]}
>

<View style={{ flex: 0.8 }}>


<View style={{ flex: 0.25, alignItems: 'center' }}>



</Animated.View>
)}
</>
);
};

const styles = StyleSheet.create({
searchView: {
position: 'absolute',
left: 0,
right: 0,
backgroundColor: 'white',
paddingTop: 6,
paddingBottom: 8,
paddingLeft: 10,
paddingRight: 0,
zIndex: 3,
},
searchIcon: {
flex: 1,
position: 'absolute',
right: 20,
top: 13,
overflow: 'hidden',
zIndex: 3,
},
searchContainer: {
flex: 1,
flexDirection: 'row',
},
});

export default forwardRef(Searchbar);

@edstbbz
Copy link
Author

edstbbz commented Jun 22, 2023

0.67.5

2.mov

0.72.0

1.mov

@cortinico cortinico added the Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. label Jun 23, 2023
@github-actions
Copy link

⚠️ Missing Reproducible Example
ℹ️ It looks like your issue is missing a reproducible example. Please provide either:

@edstbbz
Copy link
Author

edstbbz commented Jun 23, 2023

@github-actions github-actions bot added Needs: Attention Issues where the author has responded to feedback. and removed Needs: Author Feedback labels Jun 23, 2023
@cortinico cortinico added the 0.72 label Jun 23, 2023
@edstbbz
Copy link
Author

edstbbz commented Jun 29, 2023

Is there any progress in this matter?

@vksgautam1986
Copy link

any idea or direction how to resolve it

@redpanda-bit
Copy link

redpanda-bit commented Aug 8, 2023

Hey @edstbbz try running the animation inside a useEffect that reacts to isShowInput like so:

useEffect(() => {
  if (isShowInput) {
    runAnimate(0, true);
  } else {
    runAnimate(1, false);
  }
}, [isShowInput]);

My best guess is that it you are mounting the component and running the animation right after mounting the component. This reactive approach waits for the isShowInput flag to be true before animating.

@ArjunPatidarRadix
Copy link

I'm getting the same issue as well
webraptor/react-native-deck-swiper#109
with the latest version 0.72.4

@DeniferSantiago
Copy link

This only happens in version 0.72.x with useNativeDriver, without useNativeDriver everything is fine

@stianjensen
Copy link
Contributor

stianjensen commented Oct 11, 2023

Also seeing laggy and broken animations with useNativeDriver on 0.72.5 now.
The issue I was seeing is fixed here, so I backported that on my version of RN:
ae0d714

Copy link

This issue is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the Stale There has been a lack of activity on this issue and it may be closed soon. label Apr 11, 2024
Copy link

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Apr 18, 2024
@lucas-samuel01
Copy link

Im facing the same problem in react native 0.74.5, my animation does not start when the component mounts

@RichardLindhout
Copy link

web-ridge/react-native-paper-dates#442

Seems also the case in our library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API: Animated Needs: Attention Issues where the author has responded to feedback. Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Stale There has been a lack of activity on this issue and it may be closed soon.
Projects
None yet
Development

No branches or pull requests

10 participants