Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Can I get the position of scrollbar in ui module?
-
@mikael said:
@lpl, maybe use reverse logic to adding new content. If you are down far enough, remove content from the beginning, move the remaining labels up and adjust scroll_offset so that this is not visible to user.
Then you need to implement the ”add content to top” logic as well.
Might be a performance problem there, but worth trying.
I have made this. But the content size of a scrollview is limited. So if I have a long text, then I can't finish the text by using one scrollview.
-
@lpl, I think I understood. The idea was to not let the content grow beyond a specific limit, by removing content from the start and shifting the scroll position back up again, equal to the height of the removed content, thus creating the illusion of an infinite scroll with a constant amount of content.
You said you had implemented this. What went wrong?
-
@mikael Sorry, my English is not good. I mean I have made like 8 labels move up or down when I scrolled the scrollbar. But content size of the scrollview( http://omz-software.com/pythonista/docs/ios/ui.html#ui.ScrollView.content_size) is limited. This means the Scrollview is not infinite.
-
@lpl, please re-read my previous post. Note how we would NOT keep scrolling down, just making it look like it, thus no problem with a finite ScrollView.
-
@mikael I just find a way to make an unlimited content_size. By changing the size in the code.
-
I wonder if you'd rather use TableView instead of scrollview?
i dont think scrollview has a contentsize limit -- but if you are adding labels with text you might certainly reach a memory limit if you have 1000's of subviews!
TableView lets you be much more memory efficient, because the tableview cells are only created on demand.
-
@JonB We can break down the limitation in the code. And we can use several subviews. When we scroll, if one subview is hidden(can't be seen by users), then we can move the subview from the top side to the other side. So we don't need many subviews.
-
That is what tableview does for you already, plus you don't have to manage where the subviews go, just the order and number.
-
@JonB But I can't get the position of the scrollbar.
-
@lpl, if I understand correctly, this is a markedly different approach where you do not worry about details like scroll position, but instead focus on creating a custom ListDataSource that will be dynamically polled whenever a new list item is needed.
-
@mikael I need to know the location to pre-load the next page of a book from the website. If a user almost finishes this page, I will pre-load the next one.
-
@lpl, look at TableView.data_source and the tableview_cell_for_row method. @JonB, is it the case that this is only called when needed?
-
@mikael yes, I think so. I have a TableView with 10000 rows and cell_for_row is only called for displayed rows, hopefully 😀
-
Yup, only called when needed. You can also create tableview cells offline, and serve them up in tableview_cell_for_row. For instance, you could prefetch next page.
Of course, this sounds now like a webview might be more suited, if the book is HTML
-
I made it. By using label and scrollview, I just need about 15 labels to display a lot of words. And when I almost read the page(by using the postion of the scrollbar), I pre-load the next one and change the content_size of the scrollbar. Just pure python.
-
@lpl, nice. Care to share, for example as a gist?
-
@mikael Still working on other feathers. But I will share all the codes on my github in the future.
-
@mikael Done. But the reader has some 18+ sites. Be careful. https://github.com/yjqiang/yj_ebook_reader Execute eimg_reader.py or ebook_reader.py.