You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by GitBox <gi...@apache.org> on 2020/08/11 08:30:53 UTC

[GitHub] [incubator-weex-site] zsmjhtn edited a comment on issue #589: ios该怎么一次pop两个页面呢

zsmjhtn edited a comment on issue #589:
URL: https://github.com/apache/incubator-weex-site/issues/589#issuecomment-671806241


   3种比较合理的方式:
   
   1.原生实现:在原生用一个链表来维护栈,每个viewcontroller入栈出栈,都会更新链表。当你需要pop多个页面,在链表里遍历搜索,你想要popTo(“[{name,path,targetIncluded}]”)的那个viewcontroller,再此viewcontroller之后的所有页面,加入到一个popList,遍历结束后原生直接finish掉popList里所有viewcontroller。(weex每个页面有个自定义的path,viewcontroller可以通过getUri获取path,原理就是对path进行匹配)
   
   2.原生eventbus
   
   3.Js实现:在Js里加2个自定义api:
       $push(url, ()=>{} )  
       $pop(v)
   
   $push到下个页面时,带上一个callback,将callback挂载在weex的跨页面的全局对象Q上,并在Q加一个$puuid属性,每次自增,以<puuid,callbak>形式存储在全局对象Q上。 并加puuid加入到url的param中。
   
   当在下一个页面$pop(v)时,可以获取param.puuid, 搜索全局对象Q上对应puuid的callback,触发之。
   
   这样就可以实现下一页面的pop事件,会触发前一页面push事件所传递的回调函数。只要把回调函数写成pop自身,就可以实现你的需求
   
   PS:weex的全局对象Q不一定好找,在0.28的sandbox模型中,weex页面很可能没有一个全局对象可供使用了。第三种方法会失效。(0.18版本我是挂载在Date )


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org