Skip to content

useAnimatedScrollHandler fails to update the handler on the web #5488

Closed

Description

@gaearon

Description

This should swap out the scroll handler every second.

This works on native. On the web, you'll always see handler 2 being printed.

import * as React from 'react'
import {View} from 'react-native'
import Animated, {
  useAnimatedScrollHandler,
  runOnJS,
} from 'react-native-reanimated'

export default function App() {
  const [flip, setFlip] = React.useState(false)
  React.useEffect(() => {
    let id = setInterval(() => setFlip(f => !f), 1000)
    return () => clearInterval(id)
  }, [])

  function print1() {
    console.log('handler 1')
  }
  function onScroll1() {
    'worklet'
    runOnJS(print1)()
  }
  const obj1 = {
    onScroll: onScroll1,
  }

  function print2() {
    console.log('handler 2')
  }
  function onScroll2() {
    'worklet'
    runOnJS(print2)()
  }
  const obj2 = {
    onScroll: onScroll2,
  }

  const handler = useAnimatedScrollHandler(flip ? obj1 : obj2)

  return (
    <View style={{flex: 1, height: 300, flexDirection: 'row'}}>
      <Animated.FlatList
        onScroll={handler}
        style={{flex: 1, backgroundColor: 'red'}}
        contentContainerStyle={{
          paddingTop: 1000,
        }}
      />
    </View>
  )
}

Steps to reproduce

See above

Snack or a link to a repository

see above

Reanimated version

3.6.0

React Native version

0.72.5

Platforms

Web

JavaScript runtime

None

Workflow

None

Architecture

None

Build type

None

Device

None

Device model

No response

Acknowledgements

Yes

Activity

  1. github-actions commented on Dec 11, 2023

    @github-actions

    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?

  2. gaearon commented on Dec 11, 2023

    @gaearon
    ContributorAuthor

    It does.

  3. gaearon commented on Dec 11, 2023

    @gaearon
    ContributorAuthor

    It would be nice if the bot offered a Snack link that already contains reanimated. I don't understand how to add packages to Snacks.

  4. gaearon commented on Dec 11, 2023

    @gaearon
    ContributorAuthor

    I guess I've mentioned this in #5360 before in the "web" section but it's distinct enough that it deserves a separate issue.

  5. szydlovsky commented on Apr 17, 2024

    @szydlovsky
    Contributor

    Fixed by: #5845

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Missing reproThis issue need minimum repro scenarioNeeds reviewIssue is ready to be reviewed by a maintainerPlatform: WebThis issue is specific to web

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions