Skip to content

Conversation

@tjzel
Copy link
Collaborator

@tjzel tjzel commented Jul 19, 2023

Summary

  • Remove redundant return of -1 from queueMicrotask that remained there when it was changed from setImmediate.
  • Add safe default fallbacks for scrollEventThrottle in Animated.ScrollView and Animated.FlatList.

We go from

if (!restProps.scrollEventThrottle) {
  restProps.scrollEventThrottle = 1;
}

to

  if (!('scrollEventThrottle' in restProps)) {
    restProps.scrollEventThrottle = 1;
  }

Because if user deliberately sets scrollEventThrottle to 0 we would override it.

Test plan

Test code for scrollEventThrottle, just fiddle a bit with this prop and see the outcome in the console.
import React from 'react';
import { ScrollView, View, StyleSheet, FlatList } from 'react-native';
import Animated from 'react-native-reanimated';

const data = [1];

export default function App() {
  const lastTimestamp = React.useRef(performance.now());
  function onScroll() {
    const now = performance.now();
    const delta = now - lastTimestamp.current;
    lastTimestamp.current = now;
    console.log('onScroll', delta);
  }

  return (
    <View style={styles.container}>
      <ScrollView onScroll={onScroll}>
        <View style={[styles.item, { backgroundColor: 'pink' }]} />
      </ScrollView>
      <Animated.FlatList
        data={data}
        onScroll={onScroll}
        renderItem={() => (
          <View style={[styles.item, { backgroundColor: 'navy' }]} />
        )}
      />
      <FlatList
        data={data}
        onScroll={onScroll}
        renderItem={() => (
          <View style={[styles.item, { backgroundColor: 'yellow' }]} />
        )}
      />
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flexDirection: 'row',
  },
  item: {
    height: 4000,
    flex: 1 / 3,
  },
});

@tjzel tjzel changed the title Random fixes and changes Add safe default fallback for scrollEventThrottle and remove return from queueMicrotask Jul 20, 2023
@tjzel tjzel marked this pull request as ready for review July 20, 2023 09:08
// to have continuous scroll events and
// react-native defaults it to 50 for FlatLists.
// We set it to 1 so we have peace until
// there are 960FPS screens.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// there are 960FPS screens.
// there are 960 fps screens.

} else {
exportedModule = new NativeReanimated();
}
const NativeReanimatedModule = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use exportedModule as for now.

// Set default scrollEventThrottle, because user expects
// to have continuous scroll events.
// We set it to 1 so we have peace until
// there are 960FPS screens.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// there are 960FPS screens.
// there are 960 fps screens.

}

export const callMicrotasks = shouldBeUseWeb()
export const callMicrotasks = IS_WEB
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look at line #9 😎

Copy link
Member

@tomekzaw tomekzaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

approvele

@tjzel tjzel added this pull request to the merge queue Jul 20, 2023
Merged via the queue into main with commit 8a40f97 Jul 20, 2023
@tjzel tjzel deleted the @tjzel/random-changes branch July 20, 2023 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants