JoshDSommer / nativescript-slides

A NativeScript plugin that is for Intro Tutorials, Image Carousels or any other slide functionality
Other
70 stars 32 forks source link

Render unnormal when slideContainer addChild async #80

Open imwalson opened 7 years ago

imwalson commented 7 years ago

I'm trying to add child to the slide container async way dynamically (for example,in the callback of a http request).however,the Interface become unnormal and slide container can't swipe.

To verificate this,just change the file 'dynamic-page.ts' of the demo in line 24,like setTimeout(function() { slideContainer.addChild(getSlide("Page " + i, "slide-" + i)); }, 100); and run.

May be use Template and bindingContext (like the Repeater and Listview) is a better way?

Thanks.

andreasotto commented 7 years ago

I have the same problem and stuck with that for many hours. Is there any solution in sight?!??!

I'm adding slides with an onTap method and it breaks exactly that way you described here (mixes up content over and over and sliding is broken).

Reproduce:

let slideContainer;

// this is working as expected:
export function onSlideContainerLoaded(args) {
  slideContainer = <slides.SlideContainer>args.object;
  slideContainer.addChild(exports.getSlide("Page 1"));
  slideContainer.addChild(exports.getSlide("Page 2"));
  slideContainer.addChild(exports.getSlide("Page 3")); 
}

// this then mixes up everything:
export function onButtonTap() {
  slideContainer.addChild(exports.getSlide("Page 4"));
  slideContainer.addChild(exports.getSlide("Page 5"));
  slideContainer.addChild(exports.getSlide("Page 6"));
}

Seems to be the same than in #63

JoshDSommer commented 7 years ago

Thanks for the feed back @andreasotto and @imwalson. I'll look into this more when i have a chance. Off the top of my head I don't have a solution, sorry :(

imwalson commented 7 years ago

As the appSettings is sync,so I first converts the data to string and then storage to appSettings in advance: appSettings.setString("mydata",JSON.stringify(fetchResult)); When use it, like this: JSON.parse(appSettings.getString("mydata"))

Just the temporarily solution,the disadvantage is that i can't get result timely, the data delayed.

imwalson commented 7 years ago

Maybe we can use UIScrollView to create a slides on ios,like some native slides library does.I have written a "nativescript-swiper" plugin for ios based on UIScrollView just know :https://github.com/imwalson/nativescript-swiper.Welcome contributors and issues. @andreasotto @TheOriginalJosh

toddanglin commented 7 years ago

This issue is very similar to #63 (Perhaps we should link/close one of these threads to consolidate feedback)

I posted one work around there if you need to create dynamic slides at runtime. In short, you can just create the entire SlideContainer dynamically (along with the slides) and then add to the page at anytime. Doesn't address the challenge of dynamically adding slides one at a time (via a button tap), but I suppose you could "destroy"/removeChild and recreate the SlideContainer with each tap.