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.

Getting current page item info

See original GitHub issue

Hi everyone,

I have a simple question:

In which event I can get current page item?

Here is the simpflied version of my code:

renderPage(item) { let tmpConnectionOpacity = 0.25 let tmpInUseOpacity = 0.25 return ( <View key={item.id}> <TouchableOpacity> <Panel panelName={item.name} connectionOpacity={tmpConnectionOpacity} inUseOpacity={tmpInUseOpacity} /> </TouchableOpacity> </View> ); } <ViewPager style={inlineStyles.panelPages} onPageSelected={this.onPageSelected} ref={(viewPager) => {this.viewPager = viewPager}}> {this.context.cloudData.panelList.map(panel => this.renderPage(panel))} </ViewPager>

I just want to get the current page item information. Such as key or index, so I will be able to process that information. OnPageSelected event doesn’t meet my requirements.

Thx in advance.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
mustapha-ghlissicommented, Nov 26, 2019

This how you can do it:


onPageScroll = ({nativeEvent}) => {
        this.setState({
            activeStep: nativeEvent.position
        });
}

then pass the prev function to the ViewPager component

<ViewPager 

onPageScroll={this.onPageScroll}
>
.............
</ViewPager>
3reactions
brunocrpontescommented, Oct 21, 2019

Yes, it will give the same position. You don’t have a way to access the current position directly from ViewPager component, you need to store it and change the value based on events like onPageScroll or onPageSelected.

function Component(props) {
  //by default the initialPosition props is 0, set as initial value of currentPage too...
  const [currentPage, setCurrentPage] = useState(0);

  {... component code }
  const onPageScroll = (event) => {
    const {position} = event.nativeEvent;
    if(position !== currentPosition) {
      setCurrentPosition(position);
    }
  } 

 return (
  <ViewPager onPageScroll={onPageScroll}>
    ... your pages
  </ViewPager> 
 )
}

If you need the current position after render, just use currentPosition.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Get The Current Page in Sitecore - Jon D Jones
Sitecore Instance: To get information about the current item, you can use the Sitecore. · LinkManager: Through the Sitecore. · Sitecore MVC ...
Read more >
How to get current page using start index, items per page, total ...
Show activity on this post. For example, let's say: $startIndex = 21; $totalItems = 100; $itemsPerPage = 10; $totalPages = ceil($totalItems / $ ......
Read more >
Getting current page item info · Issue #78 - GitHub
I just want to get the current page item information. Such as key or index, so I will be able to process that...
Read more >
client object model - Get Current list item
The example demonstrates how to retrieve current List Item via JSOM: ... Below is if your URL will contain the ListItem ID value...
Read more >
How to get the Current page's URL to an Item? — oracle-tech
<script type="text/javascript"> document.getElementById("FIELDNAME").value = document.URL; </script> Replace FIELDNAME with the page ...
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