UnityTech / UIWidgets

UIWidget is a Unity Package which helps developers to create, debug and deploy efficient, cross-platform Apps.
Other
1.97k stars 256 forks source link

Can i have a sample for RefreshIndicator? #425

Closed kou-yeung closed 4 years ago

kou-yeung commented 4 years ago

I use RefreshIndicator to make a "Pull to refresh".

When i download data from server and call "resolve"

Window.instance.run(() => this.ResolveSync()); will show error "Window.instance == null"

sample code for RefreshIndicator.onRefresh new RefreshIndicator ( onRefresh: RefreshList )

Promise RefreshList() { return new Promise((resolve, reject) => { using (var client = new WebClient()) { client.DownloadStringCompleted += (str, err) => { resolve(); }; client.DownloadStringAsync(new Uri("xxx"), null); } }); }

zhuxingwei commented 4 years ago

Hi, since you are using an async call to update the UI, your have to find the target window before calling Window.instance.run. You can solve this problem by surrounding Window.instance.run(..) with a getScope call, Please read this section https://github.com/UnityTech/UIWidgets#using-window-scope for the details.

kou-yeung commented 4 years ago

thanks~