Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于delayInit的问题 #232

Closed
xchengDroid opened this issue Oct 22, 2019 · 12 comments
Closed

关于delayInit的问题 #232

xchengDroid opened this issue Oct 22, 2019 · 12 comments
Labels
enhancement fixing 正在修复 need more detail 不符合issue规范,低优先级 pending release 待发布正式版

Comments

@xchengDroid
Copy link

如果我创建BasePop时设置了delayInit,我在继承的BasePopWindow里面在哪调用findViewById,没有回调函数供我初始化组件

@razerdp razerdp added the need more detail 不符合issue规范,低优先级 label Oct 22, 2019
@razerdp
Copy link
Owner

razerdp commented Oct 22, 2019

在你调用delayInit之后.

@razerdp
Copy link
Owner

razerdp commented Oct 22, 2019

就像你在activity里任意地方setContentView()之后才可以findviewbyid找到view,basepopup也是在你delayinit()调用后才能findview,在哪里调用,就在它之后初始化,没有任何限制的。

@xchengDroid
Copy link
Author

如果我在 popwindow里面需要写业务逻辑,我需在重写 delayInIt()里面做findViewById setListener操作吗?我没看到其他合适的可以处理的方法!我的意思是应该需要提供一个initView的地方或者想Fragment 里面 onViewCreated 之类的,不管我是不是delayInit,这个初始化方法都会被调用!可以统一处理业务

@xchengDroid
Copy link
Author

感谢作者编写这么好的库!给我省了时间!送上10元略表感谢

@xchengDroid
Copy link
Author

主要我不想再activity里面调用pop一些操作!只在activity里面调用 show 和 dismiss方法!其他的组件初始化全部在 pop里面执行!所以我觉得是否可以提供一个 不管我是不是delayInit 都能处理findViewById 和 setListener的回调方法

@razerdp
Copy link
Owner

razerdp commented Oct 23, 2019

首先感谢你的建议,但是首先有一点需要明确的是。。。BasePopup设计初衷就是紧跟系统原生PopupWindow的设计,BasePopup主要做的是去繁就简。

其次为什么没有你所说的方法,是因为现在的框架就已经有了这个方法,同时还是你必须实现的方法。。。

而且,当onXXX()多了,那么你的思路就不得不按照我所设计的onXXX()进行,就如activity里你setContentView()之后为啥没有onViewInflated()回调让我去findView?,delayInit()没有强要求回调的原因正是如此,我不希望开发者受限于我所提供的api,而是把最大的控制权让给开发者去开发出他们天马行空的功能。

最后,针对你所说的问题,在上面的回答和这篇回答里我都提供了解决方案了,顺带附上代码给你吧。。。

public class DemoPopup extends BasePopupWindow {
    public DemoPopup(Context context) {
        super(context,true);

        //方法一
        //在初始化之前做你任何想做的
        delayInit();
        //findView()
    }

    @Override
    public View onCreateContentView() {
        //方法二
        //该方法无论是否delayInit()都会在初始化的时候回调
        View contentView = createPopupById();

        contentView.findViewById()
        return contentView;
    }
}

@xchengDroid
Copy link
Author

解决方案我是可以找到的,其实我就是想统一有一个方法!可能每个人的思想不太一样吧!如果在onCreateContentView() 里面处理的话,就不能调用 自带的 pop.findViewById。delayInit()方法里面处理又不能处理非delayInit的情况,看来我需要自己做抽象判断了

@razerdp
Copy link
Owner

razerdp commented Oct 23, 2019

嗯嗯,确实如你所说不能用到findViewById(),同时我也突然想起似乎对butterknife这种注入也不太友好,我下一个版本加一下onInit()吧。

@xchengDroid
Copy link
Author

是的 类似Fragment都有 onViewCreated方法,因为你这个和activity还不太一样!activity是主动设置setContentView(),basePop 是通过回调的方法返回View,提供onInit 不会和外部调用findViewById冲突

@razerdp
Copy link
Owner

razerdp commented Nov 24, 2019

onInit已添加,另外经过思考,delayInit放在构造器对用户并不友好,因此下一个版本将会放弃,并添加lazypopupwindow,而且lazypopupwindow的初始化时机将会在调用show()方法,也就是说不需要进行主动调用inity,当然我也会保留主动init的方式,毕竟有可能需要提前init的

@razerdp razerdp added fixing 正在修复 pending release 待发布正式版 and removed TODO labels Nov 24, 2019
@xchengDroid
Copy link
Author

请问啥时候更新2.2.2啊

@razerdp
Copy link
Owner

razerdp commented Nov 27, 2019

大约年底

razerdp added a commit that referenced this issue Jun 29, 2021
fixed #263,fixed #262,fixed #260,fixed #249,fixed #248,fixed #247,fixed #244,fixed #242,fixed #240,fixed #238,fixed #236,fixed #232,fixed #226,fixed #213,fixed #210,fixed #207,fixed #184
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement fixing 正在修复 need more detail 不符合issue规范,低优先级 pending release 待发布正式版
Projects
None yet
Development

No branches or pull requests

2 participants