Skip to content

Commit

Permalink
fix: safely handle mutable nullable variables (#4)
Browse files Browse the repository at this point in the history
* fix: safely handle mutable nullable variables

* ci: added publish workflow
  • Loading branch information
bang9 committed Jun 14, 2023
1 parent 3ba9bb6 commit 4892567
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 12 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: npm publish

on:
workflow_dispatch:
inputs:
version:
description: 'version'
required: true
type: string

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version: 16.x
- run: yarn install --immutable
- name: 'set environments'
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" >> .npmrc
git config --global user.email "sha.sdk_deployment@sendbird.com"
git config --global user.name "sendbird-sdk-deployment"
- name: 'publish'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
yarn release-it ${{ github.event.inputs.version }} --ci
Original file line number Diff line number Diff line change
Expand Up @@ -101,42 +101,42 @@ class MaintainVisibleScrollPositionHelper(
* has been updated.
*/
override fun updateScrollPosition() {
if ((mConfig == null) || (mFirstVisibleView == null) || (mPrevFirstVisibleFrame == null)) {
return
}

val firstVisibleView: View? = mFirstVisibleView!!.get()
val config = mConfig ?: return
val firstVisibleView = mFirstVisibleView?.get() ?: return
val prevFirstVisibleFrame = mPrevFirstVisibleFrame ?: return
val newFrame = Rect()
firstVisibleView!!.getHitRect(newFrame)

firstVisibleView.getHitRect(newFrame)

if (mHorizontal) {
val deltaX: Int = newFrame.left - mPrevFirstVisibleFrame!!.left
val deltaX: Int = newFrame.left - prevFirstVisibleFrame.left
if (deltaX != 0) {
val scrollX: Int = mScrollView.scrollX
mScrollView.scrollTo(scrollX + deltaX, mScrollView.scrollY)
mPrevFirstVisibleFrame = newFrame
if (mConfig!!.autoScrollToTopThreshold != null && scrollX <= mConfig!!.autoScrollToTopThreshold!!) {
if (config.autoScrollToTopThreshold != null && scrollX <= config.autoScrollToTopThreshold) {
mScrollView.reactSmoothScrollTo(0, mScrollView.scrollY)
}
}
} else {
val deltaY: Int = newFrame.top - mPrevFirstVisibleFrame!!.top
val deltaY: Int = newFrame.top - prevFirstVisibleFrame.top
if (deltaY != 0) {
val scrollY: Int = mScrollView.scrollY
mScrollView.scrollTo(mScrollView.scrollX, scrollY + deltaY)
mPrevFirstVisibleFrame = newFrame
if (mConfig!!.autoScrollToTopThreshold != null && scrollY <= mConfig!!.autoScrollToTopThreshold!!) {
if (config.autoScrollToTopThreshold != null && scrollY <= config.autoScrollToTopThreshold) {
mScrollView.reactSmoothScrollTo(mScrollView.scrollX, 0)
}
}
}
}

private fun computeTargetView() {
if (mConfig == null) return
val config = mConfig ?: return

contentView?.let { contentView ->
val currentScroll: Int = if (mHorizontal) mScrollView.scrollX else mScrollView.scrollY
for (i in mConfig!!.minIndexForVisible until contentView.childCount) {
for (i in config.minIndexForVisible until contentView.childCount) {
val child: View = contentView.getChildAt(i)
val position: Float = if (mHorizontal) child.x else child.y
if (position > currentScroll || i == contentView.childCount - 1) {
Expand Down

0 comments on commit 4892567

Please sign in to comment.