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.

ViewPager does not load when using a Map function

See original GitHub issue

🐛 Bug Report

When using a map function to populate the ViewPager, i keep getting the error Screen Shot 2020-02-19 at 12 32 02 PM

I am generating the viewpager like so

<ViewPager
    selectedIndex={this.state.currentSection}
onSelect={(index) => this.setCurrentSection(index)}
>
{
    this.state.audit.sections.map((section, index) => {
        return (
            <Layout>
                <Text style={auditFormScreenStyles.sectionHeaderText}>{section.label}</Text>
        </Layout>
    )
    })
}
</ViewPager>

I know the data is valid because i can use a horizontal flatlist and it works and renders just fine. I can get the ViewPager to render two other ways as well. 1, by copying the doc examples like so

<ViewPager
    selectedIndex={this.state.currentSection}
onSelect={(index) => this.setCurrentSection(index)}
>
   <Layout>
      <Text>Hello</Text>
   </Layout>
   <Layout>
      <Text>World</Text>
   </Layout>
</ViewPager>

and by modfiying the onSelect prop to

<ViewPager
    selectedIndex={this.state.currentSection}
onSelect={(index) => () => this.setCurrentSection(index)}
>
{
    this.state.audit.sections.map((section, index) => {
        return (
            <Layout>
                <Text style={auditFormScreenStyles.sectionHeaderText}>{section.label}</Text>
        </Layout>
    )
    })
}
</ViewPager>

Modifying the onSelect prop will get it to render, but swiping doesn’t work properly of course

To Reproduce

Steps to reproduce the behavior: Generate a ViewPager using the map method on an array

Expected behavior

ViewPager renders and swipes normally

Link to runnable example or repository (highly encouraged)

UI Kitten and Eva version

Package Version
@eva-design/eva 4.4.0
@ui-kitten/components 4.4.0

Environment information

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz
  Binaries:
    Node: 13.8.0 - /usr/local/bin/node
    npm: 6.13.7 - /usr/local/bin/npm
  SDKs:
    iOS SDK:
      Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1
  IDEs:
    Xcode: 11.3.1/11C504 - /usr/bin/xcodebuild
  npmPackages:
    react: 16.9.0 => 16.9.0 
    react-native: 0.61.5 => 0.61.5

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
eyalyolicommented, Sep 10, 2020

There is another problem in the same situation, on initial render index 0 is selected, the map that I’m using is based on an async function, so the initially selected index 0 is selected from empty array or null, it throws a weird animation error randomly.

what I did is to is:

onSelect={
          results
            ? (i) => {
                if (!isNaN(i)) setSelectedIndex(i);
              }
            : null
        }
1reaction
wigleyjcommented, Feb 25, 2020

I seemed to have fixed this error. For some reason when iterating over a map function, the onSelect method would pass a NaN value. I fixed this by changing the onSelect method to

onSelect={(index) => {
    if(!isNaN(index)){
        this.setCurrentSection(index)
    }
}}

still unsure as to why it was only when using the map function.

Read more comments on GitHub >

github_iconTop Results From Across the Web

View Pager not refresh the map - android - Stack Overflow
I have a View Pager which contain four fragments , one of them there is a fragment which contains Map. When I come...
Read more >
Create swipe views with tabs using ViewPager2
Swipe views allow you to navigate between sibling screens, such as tabs, with a horizontal finger gesture, or swipe. This navigation pattern is...
Read more >
ArcGIS map crashes under android ViewPager2
I tried to make an ArcGIS map work under an android ViewPager2. ... in the view pager, then back to the map, the...
Read more >
Android TabLayout and ViewPager - DigitalOcean
Whoops, the scrolling is fixed but the ListView is displaying only one row now. Hence a ListView should not be used with our...
Read more >
How to Implement Google Map Inside Fragment in Android?
Open a new project. · We will be working on Empty Activity with language as Java. Leave all other options unchanged. · Name...
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