Giter VIP home page Giter VIP logo

Comments (3)

radixdev avatar radixdev commented on July 22, 2024

Hi @egor-n ,

We can reproduce the issue and will update this thread with a fix. It does appear that the findFirstVisibleItemPosition() methods are firing too late/early depending on the padding, like you're seeing.

from braze-android-sdk.

radixdev avatar radixdev commented on July 22, 2024

Hi @egor-n ,

Upon further inspection of the reported issue it doesn't look like we can support adding padding to the RecyclerView in that way. I would suggest some combination of the following (3. specifically):

  1. Modifying the dimens/com_braze_content_cards_divider_height value
  2. Adding margin/padding to the surrounding container view of the RecyclerView instead of the RecyclerView itself.
  3. Modifying ContentCardsDividerItemDecoration

from braze-android-sdk.

egor-n avatar egor-n commented on July 22, 2024

@radixdev I ended up adding a new ItemDecoration like so:

class VerticalPaddingDecoration(
    private val paddingPx: Int
) : RecyclerView.ItemDecoration() {
    override fun getItemOffsets(
        outRect: Rect,
        view: View,
        parent: RecyclerView,
        state: RecyclerView.State
    ) {
        val itemPosition = parent.getChildAdapterPosition(view)
        if (itemPosition == RecyclerView.NO_POSITION) {
            return
        }
        if (itemPosition == 0) {
            outRect.top = paddingPx
        }
        val adapter = parent.adapter
        if (adapter != null && itemPosition == adapter.itemCount - 1) {
            outRect.bottom = paddingPx
        }
    }
}

// custom ContentCardsFragment:
class MyContentCardsFragment : ContentCardsFragment() {
    override fun onViewStateRestored(savedInstanceState: Bundle?) {
        super.onViewStateRestored(savedInstanceState)
        contentCardsRecyclerView?.let { recyclerView ->
            recyclerView.addItemDecoration(
                VerticalPaddingDecoration(
                    resources.getDimensionPixelOffset(
                        R.dimen.my_vertical_padding
                    )
                )
            )
        }
    }
}

from braze-android-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.