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

Fix synchronous layout. #1584

Merged
merged 5 commits into from
Jan 8, 2021
Merged

Fix synchronous layout. #1584

merged 5 commits into from
Jan 8, 2021

Conversation

Szymon20000
Copy link
Contributor

@Szymon20000 Szymon20000 commented Dec 31, 2020

Description

Fixes: #1576
Fixes: #1579
In #1501 we forgot that sometimes we have to notify mounting listeners about a mounting. The problem we had with operation running out of order won't happen when we notify listeners after the mounting block is prepared. That's what I want to do in the pr.

It's also important to understand that we won't capture a new mounting block by calling setNeedsLayoutbecause we add NodesManager as an observer only for the time of syncLayout.

Changes

Add setNeedsLayout after sync layout.

Test code and steps to reproduce

import React, { useEffect } from "react";
import { StyleSheet, View } from "react-native";
import { ReText } from 'react-native-redash';
import Animated, {
  useAnimatedStyle,
  useDerivedValue,
  useSharedValue,
  withSpring,
  withTiming,
} from "react-native-reanimated";

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  card: {
    position: "absolute",
    top: 0,
    left: 0,
    width: 100,
    height: 50,
  },
});

const DynamicSpring = () => {
  const x = useSharedValue('0deg');
  useEffect(() => {
    x.value = withTiming('300deg', { duration: 5000 });
  });
  
  return (
    <View style={styles.container}>
      <ReText
        text={x}
        style={{ color: "black", fontVariant: ["tabular-nums"] }}
      />
    </View>
  );
};

export default DynamicSpring;

Checklist

  • Included code example that can be used to test this change
  • Updated TS types
  • Added TS types tests
  • Added unit / integration tests
  • Updated documentation
  • Ensured that CI passes

@Szymon20000 Szymon20000 marked this pull request as draft January 7, 2021 07:09
@Szymon20000 Szymon20000 marked this pull request as ready for review January 7, 2021 07:16
@Szymon20000 Szymon20000 merged commit bee08b9 into master Jan 8, 2021
@Szymon20000 Szymon20000 deleted the @szymon/fix_sync_layout branch January 8, 2021 08:05
rpavlovs pushed a commit to rpavlovs/react-native-reanimated that referenced this pull request Jan 12, 2021
## Description

Fixes: software-mansion#1576
Fixes: software-mansion#1579
In software-mansion#1501 we forgot that sometimes we have to notify mounting listeners about a mounting. The problem we had with operation running out of order won't happen when we notify listeners after the mounting block is prepared. That's what I want to do in the pr.

It's also important to understand that we won't capture a new mounting block by calling `setNeedsLayout`because we add NodesManager as an observer only for the time of syncLayout.

## Changes

Add setNeedsLayout after sync layout.

## Test code and steps to reproduce

```JS
import React, { useEffect } from "react";
import { StyleSheet, View } from "react-native";
import { ReText } from 'react-native-redash';
import Animated, {
  useAnimatedStyle,
  useDerivedValue,
  useSharedValue,
  withSpring,
  withTiming,
} from "react-native-reanimated";

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
  card: {
    position: "absolute",
    top: 0,
    left: 0,
    width: 100,
    height: 50,
  },
});

const DynamicSpring = () => {
  const x = useSharedValue('0deg');
  useEffect(() => {
    x.value = withTiming('300deg', { duration: 5000 });
  });
  
  return (
    <View style={styles.container}>
      <ReText
        text={x}
        style={{ color: "black", fontVariant: ["tabular-nums"] }}
      />
    </View>
  );
};

export default DynamicSpring;
```
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.

screen not always updating when using TextInput useReanimatedProps with custom component not updating on iOS
2 participants