-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Run listeners when calling sv.modify (#5306)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect. --> ## Summary This PR fixes `modify` method of shared value so that it runs all listeners after the change even if the reference to the value does not change. Co-authored-by: @kmagiera Co-authored-by: @piaskowyk ## Test plan ModifyExample.tsx
- Loading branch information
Showing
6 changed files
with
106 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { Button, StyleSheet, View } from 'react-native'; | ||
|
||
import React from 'react'; | ||
import { | ||
runOnUI, | ||
useDerivedValue, | ||
useSharedValue, | ||
} from 'react-native-reanimated'; | ||
|
||
export default function ModifyExample() { | ||
const sv = useSharedValue([1]); | ||
|
||
const handleModify = () => { | ||
sv.modify((value) => { | ||
'worklet'; | ||
value.push(value.length + 1); | ||
return value; | ||
}); | ||
}; | ||
|
||
const handleModifyWithoutArgument = () => { | ||
sv.modify(); | ||
}; | ||
|
||
useDerivedValue(() => { | ||
console.log('useDerivedValue', sv.value); | ||
}); | ||
|
||
const handleRead = () => { | ||
console.log('JS', sv.value); | ||
runOnUI(() => { | ||
console.log('UI', sv.value); | ||
})(); | ||
}; | ||
|
||
return ( | ||
<View style={styles.container}> | ||
<Button title="Modify" onPress={handleModify} /> | ||
<Button | ||
title="Modify without argument" | ||
onPress={handleModifyWithoutArgument} | ||
/> | ||
<Button title="Read" onPress={handleRead} /> | ||
</View> | ||
); | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters