I guess the reason is  applications windows location,  you can try to debug
by po all the windows both in your application and Weex Playground app

the toast try to find a superview by getting the application windows.

2018-02-27 17:14 GMT+08:00 许有红 <emptywalk...@gmail.com>:

> Toast cannot be displayed in your project, but can be displayed in the
> playground. My environment is as follows:
>
> weexSDK: 0.18.0
> $ weex -v
>   v1.1.0-beta.7
> - weexpack : v0.4.7-beta.26
> - weex-builder : v0.2.13-beta.4
> - weex-devtool : v0.3.2-beta.11
> - weex-previewer : v1.3.13-beta.10
>
> The vue code is as follows:
>
> <template>
>  <list>
>    <cell @click="cellClicked(0)">
>      <text>点我有弹框</text>
>    </cell>
>  </list>
> </template>
>
> <script>
>  const { toast } = require('./util.js');
>  const navigator = weex.requireModule('navigator');
>
>  export default {
>    methods: {
>      cellClicked() {
>        const modal = weex.requireModule('modal');
>        modal.toast({
>          message: '123120----3123',
>          duration: 1,
>        });
>      }
>    }
>  }
> </script>
>
>
> According to 'https://github.com/alibaba/weex/issues/2183', the following
> solution is found:
>
> - (void)toast:(NSString *)message duration:(double)duration
> {
>    WXAssertMainThread();
>    // UIView *superView = [[[UIApplication sharedApplication] windows]
> objectAtIndex:0];
>    // 将上行的代码该为下行就好了。
>    UIView *superView = [[[UIApplication sharedApplication] windows]
> lastObject];
>    if (!superView) {
>        superView = self.weexInstance.rootView;
>    }
>    UIView *toastView = [self toastViewForMessage:message
> superView:superView];
>    WXToastInfo *info = [WXToastInfo new];
>    info.toastView = toastView;
>    info.superView = superView;
>    info.duration = duration;
>    [[WXToastManager sharedManager].toastQueue addObject:info];
>
>    if (![WXToastManager sharedManager].toastingView) {
>        [self showToast:toastView superView:superView duration:duration];
>    }
> }
>
>
> Q:Why doesn't the same code work in my project, but in the playground?
>

Reply via email to