AnswerBun.com

Flatlist maintainVisibleContentPosition causes instant crash on iOs

Stack Overflow Asked by Ryan Pergent on November 21, 2020

I have an app with only this component:

function TestComp() {
    return (
        <FlatList
            keyExtractor={(item) => String(item)}
            data={[0, 1, 2, 3]}
            renderItem={({ item }) => (
                <View>
                    <Text>{item}</Text>
                </View>
            )}
            maintainVisibleContentPosition     <--- Causes crash
        />
    );
}

The program crashes immegiately, throwing the error:
Exception thrown while executing UI block: - [__NSCFBoolean objectForKeyedSubscript:]: unrecognized selector sent to instance 0x11bfcae48.

The crash disappears when I remove the maintainVisibleContentPosition props (but I need it).

I am on react 16.11.0, using expo sdk 38.0.0.

Any idea why this is happening?

enter image description here

2 Answers

This happens because React is expecting you to define the minimum visible position even if it's zero. So instead of just putting maintainVisibleContentPosition, try using

maintainVisibleContentPosition={{
     minIndexForVisible: 0,
  }}

Correct answer by Softasu on November 21, 2020

maintainVisibleContentPosition here is official docs

the App is crashing due because maintainVisibleContentPosition is aspecting a object

try this

maintainVisibleContentPosition={{
     minIndexForVisible: 0,
  }}

here is demo: https://snack.expo.io/@nomi9995/flastlist-fix-crash

import * as React from 'react';
import { FlatList, Text, View } from 'react-native';

export default function App() {
  return (
        <FlatList
            keyExtractor={(item) => String(item)}
            data={[0, 1, 2, 3]}
            renderItem={({ item }) => (
                <View>
                    <Text>{item}</Text>
                </View>
            )}
            maintainVisibleContentPosition={{
              minIndexForVisible: 0,
            }}
        />
    );
}

Answered by Muhammad Numan on November 21, 2020

Add your own answers!

Related Questions

Update employee manager using employeeid

1  Asked on December 19, 2020 by user8624315

   

Skipping the first step in a loop for the first iteration

2  Asked on December 19, 2020 by qua

     

Make a circular button programatically

3  Asked on December 19, 2020 by user14469311

         

How to delete enclosing braces in Vim?

4  Asked on December 19, 2020 by robottinosino

 

How to swap my list element’s name and value in R?

3  Asked on December 19, 2020 by achai

   

How can we sum the values group by from file using shell script

2  Asked on December 18, 2020 by kashif

       

How to correlate scalar values of two pandas dataframes

2  Asked on December 18, 2020 by kaleb-coberly

         

Handling arrays of hours

1  Asked on December 18, 2020 by matheus-alves

 

How can I have a C++ set with more than 1 data type?

1  Asked on December 18, 2020 by blakcy88

     

Laravel Auth Guard Users From Array

0  Asked on December 18, 2020 by gstar

   

How can if/elif/else be replaced with min() and max()?

3  Asked on December 18, 2020 by nsmedira

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP, SolveDir