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

measureInWindow returns the same when scrolling in iOS #48425

Open
thuman opened this issue Jan 2, 2025 · 4 comments
Open

measureInWindow returns the same when scrolling in iOS #48425

thuman opened this issue Jan 2, 2025 · 4 comments
Labels
Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Platform: iOS iOS applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@thuman
Copy link

thuman commented Jan 2, 2025

Description

import React, { useState, useRef } from 'react';
import { View, ScrollView, Text, StyleSheet } from 'react-native';

const App = () => {
  const viewRef = useRef(null);
  const [viewPosition, setViewPosition] = useState({ x: 0, y: 0 });
  let timer = null

  const onScroll = () => {
    console.log('onScroll')
    if (viewRef && viewRef.current) {
      try {
        viewRef.current.measureInWindow(function (x, y, width, height) {
          console.log({x, y, width, height})
          setViewPosition({ x: x, y: y });
        });
      } catch (error) {
        console.error('Error measuring the view:', error);
      }
    }
  };
  
  return (
    <ScrollView onScroll={onScroll}>
      <View style={styles.container}>
        <Text style={styles.text}>Scroll the screen</Text>
        <View ref={viewRef} style={styles.measuredView}>
          <Text style={styles.text}>This is the view to be measured x:{viewPosition.x} y:{viewPosition.y} </Text>
        </View>
        <View style={styles.bottom}></View>
      </View>
    </ScrollView>
  );
};

const styles = StyleSheet.create({
  bottom: {
    height: 700,
    width: 100,
    backgroundColor: 'red'
  },
  container: {
    flex: 1,
    alignItems: 'center',
    justifyContent: 'center',
  },
  text: {
    fontSize: 20,
    margin: 20,
  },
  measuredView: {
    width: 200,
    height: 200,
    backgroundColor: 'lightblue',
    margin: 20,
  },
});

export default App;

When scoll the ScrollView, the the viewRef's position not change. It occurs only in iOS。Android works good.

Steps to reproduce

  1. npx @react-native-community/cli@latest init AwesomeProject --version 0.76.3
  2. use the code above to replace the App.tsx
  3. run in ios simulator
  4. scroll the ScrollView

React Native Version

0.76.3

Affected Platforms

Runtime - iOS

Areas

Fabric - The New Renderer

Output of npx react-native info

System:
  OS: macOS 14.5
  CPU: (12) arm64 Apple M3 Pro
  Memory: 82.00 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.11.0
    path: ~/.nvm/versions/node/v20.11.0/bin/node
  Yarn: Not Found
  npm:
    version: 10.2.4
    path: ~/.nvm/versions/node/v20.11.0/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.5
      - iOS 17.5
      - macOS 14.5
      - tvOS 17.5
      - visionOS 1.2
      - watchOS 10.5
  Android SDK:
    API Levels:
      - "34"
      - "35"
    Build Tools:
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.1 AI-241.18034.62.2412.12266719
  Xcode:
    version: 15.4/15F31d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.12
    path: /usr/bin/javac
  Ruby:
    version: 3.1.0
    path: /Users/didi/.rvm/rubies/ruby-3.1.0/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.3
    wanted: 0.76.3
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: false

Stacktrace or Logs

no crash.

Reproducer

https://github.com/thuman

Screenshots and Videos

No response

@thuman thuman added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Jan 2, 2025
@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - 0.76.5. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot react-native-bot added Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Platform: iOS iOS applications. labels Jan 2, 2025
@react-native-bot
Copy link
Collaborator

Tip

Newer version available: You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

Warning

Missing reproducer: We could not detect a reproducible example in your issue report. Please provide either:

@sarthak-d11
Copy link
Contributor

Hey @thuman , I noticed that the npx react-native info output shows newArchEnabled: false for iOS. Could you please look into this issue with new architecture enabled?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Author Feedback Needs: Repro This issue could be improved with a clear list of steps to reproduce the issue. Newer Patch Available Platform: iOS iOS applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

No branches or pull requests

3 participants