question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SafeAreaView inside ScrollView jitters and maxes out CPU

See original GitHub issue

Description

When a SafeAreaView is placed inside a ScrollView, and the SafeAreaView has a margin, the ScrollView shakes and the CPU goes haywire.

Without the margin, CPU usage hovers at around 0.2%. With the margin, CPU usage sits at over 100%.

I’ve only tested this on my iPhone 11 simulator (running iOS 13.3) in development mode. A minimal reproducible example and gif are provided below.

React Native version:

info Fetching system and libraries information...
System:
    OS: macOS 10.15.3
    CPU: (8) x64 Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
    Memory: 485.68 MB / 16.00 GB
    Shell: 5.7.1 - /bin/zsh
  Binaries:
    Node: 12.12.0 - /usr/local/bin/node
    Yarn: Not Found
    npm: 6.11.3 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.9.1 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
    Android SDK: Not Found
  IDEs:
    Android Studio: Not Found
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.4 - /Users/chris/.sdkman/candidates/java/current/bin/javac
    Python: 2.7.16 - /usr/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.11.0 => 16.11.0 
    react-native: 0.62.2 => 0.62.2 
  npmGlobalPackages:
    *react-native*: Not Found

Steps To Reproduce

  1. Create a blank app using npx react-native init wiggle.
  2. Replace App.js with the code below.
  3. Run the app on an iPhone simulator (cd wiggle && npx react-native run-ios)

Note: Any margin value below 35 causes the issue for me. Margins >= 35 work fine. My hunch is that this is the height of the iPhone notch.

Expected Results

No jittering or CPU exhaustion, regardless of the margin applied.

Snack, code example, screenshot, or link to a repository:

Video showing problem: https://imgur.com/a/Bw7qIoq

Contents of App.js:

import React from 'react'
import { SafeAreaView, ScrollView, Text } from 'react-native'

const App = () => {
  return (
    <ScrollView>
      <SafeAreaView style={{ margin: 20 }}>
        <Text>{'wiggle\n'.repeat(100)}</Text>
      </SafeAreaView>
    </ScrollView>
  )
}

export default App

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:9

github_iconTop GitHub Comments

2reactions
safaiyehcommented, Sep 2, 2020

Hi @chrisparton1991, thanks for the issue.

Some observations when I wrap the ScrollView with SafeAreaView

    <SafeAreaView style={{ margin: 20 }}>
      <ScrollView>
          <Text>{'wiggle\n'.repeat(100)}</Text>
      </ScrollView>
    </SafeAreaView>

The jittering stops. So there must be some weird calculations being done with ScrollView children + SafeAreaView

0reactions
justindc100commented, Jul 22, 2022

Seeing this issue still

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Native ScrolView Giving warning for Flatlist
The warning appears because ScrollView and FlatList share the same logic, if FlatList run inside ScrollView, it's duplicated By the way ...
Read more >
Support for working with Dart Package Resolution ... - Morioh
Support for working with Package Configuration files as described in the Package Configuration ... ( const Duration(milliseconds: 100), (e) => DateTime.now().
Read more >
A Method for Live SQL Query Subscription in React ... - Theseus
This thesis proposes integrating the well-established embedded SQLite database into React. Native in a reactive and unintrusive manner, ...
Read more >
ternary operator 3 conditions react Code Example
render () { return ( { //Check if message failed (this.state.message === 'failed') ? Something went wrong : Everything in the world is...
Read more >
https://gitlab.parity.io/parity/mirrors/parity-sig...
isAsyncMode() alias has been deprecated, and will be removed in React 17+. ... rightOffset;return Math.max(0,o)+Math.max(0,u)}function He(t,n){return ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found