RecyclerView won't update child until I scroll

后端 未结 1 2010
不知归路
不知归路 2020-12-10 19:33

I think I\'ve read pretty much all the answers to all of the similar SO questions, and NONE of them seem to be working for me. It\'s drivin

相关标签:
1条回答
  • 2020-12-10 20:09

    That was a react-native issue ¯\_(ツ)_/¯.

    I've resolved this by intercepting requestLayout like so:

    protected boolean mRequestedLayout = false;
    
    @Override
        public void requestLayout() {
            super.requestLayout();
            // We need to intercept this method because if we don't our children will never update
            // Check https://stackoverflow.com/questions/49371866/recyclerview-wont-update-child-until-i-scroll
            if (!mRequestedLayout) {
                mRequestedLayout = true;
                this.post(new Runnable() {
                    @SuppressLint("WrongCall")
                    @Override
                    public void run() {
                        mRequestedLayout = false;
                        layout(getLeft(), getTop(), getRight(), getBottom());
                        onLayout(false, getLeft(), getTop(), getRight(), getBottom());
                    }
                });
            }
        }
    

    FINALLY it works.. Credit goes to this unsung hero who discovered the workaround.

    0 讨论(0)
提交回复
热议问题