Skip to content

Commit

Permalink
refact(Android): unify member-field naming convention in Kotlin (#1999)
Browse files Browse the repository at this point in the history
## Description

Up to now we had mixed naming conventions -> I've applied [Android
official
ones](https://developer.android.com/kotlin/style-guide#naming_2)

## Changes

Refactored whole library code so that we stick to single naming
convention

## Test code and steps to reproduce

Run any example & see that it runs as it should

## Checklist

- [x] Ensured that CI passes
  • Loading branch information
kkafar authored Jan 2, 2024
1 parent 8969d3b commit fad311a
Show file tree
Hide file tree
Showing 28 changed files with 322 additions and 379 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ class CustomSearchView(context: Context, fragment: Fragment) : SearchView(contex
setOnSearchClickListener - https://developer.android.com/reference/android/widget/SearchView#setOnSearchClickListener(android.view.View.OnClickListener)
setOnCloseListener - https://developer.android.com/reference/android/widget/SearchView#setOnCloseListener(android.widget.SearchView.OnCloseListener)
*/
private var mCustomOnCloseListener: OnCloseListener? = null
private var mCustomOnSearchClickedListener: OnClickListener? = null
private var onCloseListener: OnCloseListener? = null
private var onSearchClickedListener: OnClickListener? = null

private var mOnBackPressedCallback: OnBackPressedCallback =
private var onBackPressedCallback: OnBackPressedCallback =
object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
isIconified = true
}
}

private val backPressOverrider = FragmentBackPressOverrider(fragment, mOnBackPressedCallback)
private val backPressOverrider = FragmentBackPressOverrider(fragment, onBackPressedCallback)

var overrideBackAction: Boolean
set(value) {
Expand All @@ -46,11 +46,11 @@ class CustomSearchView(context: Context, fragment: Fragment) : SearchView(contex
}

override fun setOnCloseListener(listener: OnCloseListener?) {
mCustomOnCloseListener = listener
onCloseListener = listener
}

override fun setOnSearchClickListener(listener: OnClickListener?) {
mCustomOnSearchClickedListener = listener
onSearchClickedListener = listener
}

override fun onAttachedToWindow() {
Expand All @@ -67,12 +67,12 @@ class CustomSearchView(context: Context, fragment: Fragment) : SearchView(contex

init {
super.setOnSearchClickListener { v ->
mCustomOnSearchClickedListener?.onClick(v)
onSearchClickedListener?.onClick(v)
backPressOverrider.maybeAddBackCallback()
}

super.setOnCloseListener {
val result = mCustomOnCloseListener?.onClose() ?: false
val result = onCloseListener?.onClose() ?: false
backPressOverrider.removeBackCallbackIfAdded()
result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import androidx.fragment.app.Fragment

class FragmentBackPressOverrider(
private val fragment: Fragment,
private val mOnBackPressedCallback: OnBackPressedCallback
private val onBackPressedCallback: OnBackPressedCallback
) {
private var mIsBackCallbackAdded: Boolean = false
private var isCallbackAdded: Boolean = false
var overrideBackAction: Boolean = true

fun maybeAddBackCallback() {
if (!mIsBackCallbackAdded && overrideBackAction) {
if (!isCallbackAdded && overrideBackAction) {
fragment.activity?.onBackPressedDispatcher?.addCallback(
fragment,
mOnBackPressedCallback
onBackPressedCallback
)
mIsBackCallbackAdded = true
isCallbackAdded = true
}
}

fun removeBackCallbackIfAdded() {
if (mIsBackCallbackAdded) {
mOnBackPressedCallback.remove()
mIsBackCallbackAdded = false
if (isCallbackAdded) {
onBackPressedCallback.remove()
isCallbackAdded = false
}
}
}
53 changes: 18 additions & 35 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,22 @@ import com.facebook.react.uimanager.UIManagerModule
import com.swmansion.rnscreens.events.HeaderHeightChangeEvent

@SuppressLint("ViewConstructor")
class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(context) {
class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
val fragment: Fragment?
get() = fragmentWrapper?.fragment

var fragmentWrapper: ScreenFragmentWrapper? = null
var container: ScreenContainer? = null
var activityState: ActivityState? = null
private set
private var mTransitioning = false
private var isTransitioning = false
var stackPresentation = StackPresentation.PUSH
var replaceAnimation = ReplaceAnimation.POP
var stackAnimation = StackAnimation.DEFAULT
var isGestureEnabled = true
var screenOrientation: Int? = null
private set
private var mStatusBarStyle: String? = null
private var mStatusBarHidden: Boolean? = null
private var mStatusBarTranslucent: Boolean? = null
private var mStatusBarColor: Int? = null
private var mNavigationBarColor: Int? = null
private var mNavigationBarHidden: Boolean? = null
var isStatusBarAnimated: Boolean? = null
private var mNativeBackButtonDismissalEnabled = true

init {
// we set layout params as WindowManager.LayoutParams to workaround the issue with TextInputs
Expand Down Expand Up @@ -102,10 +95,10 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
* container when transitioning is detected and turned off immediately after
*/
fun setTransitioning(transitioning: Boolean) {
if (mTransitioning == transitioning) {
if (isTransitioning == transitioning) {
return
}
mTransitioning = transitioning
isTransitioning = transitioning
val isWebViewInScreen = hasWebView(this)
if (isWebViewInScreen && layerType != LAYER_TYPE_HARDWARE) {
return
Expand Down Expand Up @@ -169,33 +162,30 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
this.headerConfig?.toolbar?.importantForAccessibility = mode
}

var statusBarStyle: String?
get() = mStatusBarStyle
var statusBarStyle: String? = null
set(statusBarStyle) {
if (statusBarStyle != null) {
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarStyle = statusBarStyle
field = statusBarStyle
fragmentWrapper?.let { ScreenWindowTraits.setStyle(this, it.tryGetActivity(), it.tryGetContext()) }
}

var isStatusBarHidden: Boolean?
get() = mStatusBarHidden
var isStatusBarHidden: Boolean? = null
set(statusBarHidden) {
if (statusBarHidden != null) {
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarHidden = statusBarHidden
field = statusBarHidden
fragmentWrapper?.let { ScreenWindowTraits.setHidden(this, it.tryGetActivity()) }
}

var isStatusBarTranslucent: Boolean?
get() = mStatusBarTranslucent
var isStatusBarTranslucent: Boolean? = null
set(statusBarTranslucent) {
if (statusBarTranslucent != null) {
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarTranslucent = statusBarTranslucent
field = statusBarTranslucent
fragmentWrapper?.let {
ScreenWindowTraits.setTranslucent(
this,
Expand All @@ -205,33 +195,30 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
}
}

var statusBarColor: Int?
get() = mStatusBarColor
var statusBarColor: Int? = null
set(statusBarColor) {
if (statusBarColor != null) {
ScreenWindowTraits.applyDidSetStatusBarAppearance()
}
mStatusBarColor = statusBarColor
field = statusBarColor
fragmentWrapper?.let { ScreenWindowTraits.setColor(this, it.tryGetActivity(), it.tryGetContext()) }
}

var navigationBarColor: Int?
get() = mNavigationBarColor
var navigationBarColor: Int? = null
set(navigationBarColor) {
if (navigationBarColor != null) {
ScreenWindowTraits.applyDidSetNavigationBarAppearance()
}
mNavigationBarColor = navigationBarColor
field = navigationBarColor
fragmentWrapper?.let { ScreenWindowTraits.setNavigationBarColor(this, it.tryGetActivity()) }
}

var isNavigationBarHidden: Boolean?
get() = mNavigationBarHidden
var isNavigationBarHidden: Boolean? = null
set(navigationBarHidden) {
if (navigationBarHidden != null) {
ScreenWindowTraits.applyDidSetNavigationBarAppearance()
}
mNavigationBarHidden = navigationBarHidden
field = navigationBarHidden
fragmentWrapper?.let {
ScreenWindowTraits.setNavigationBarHidden(
this,
Expand All @@ -240,11 +227,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
}
}

var nativeBackButtonDismissalEnabled: Boolean
get() = mNativeBackButtonDismissalEnabled
set(enableNativeBackButtonDismissal) {
mNativeBackButtonDismissalEnabled = enableNativeBackButtonDismissal
}
var nativeBackButtonDismissalEnabled: Boolean = true

private fun calculateHeaderHeight() {
val actionBarTv = TypedValue()
Expand All @@ -253,7 +236,7 @@ class Screen constructor(context: ReactContext?) : FabricEnabledViewGroup(contex
// Check if it's possible to get an attribute from theme context and assign a value from it.
// Otherwise, the default value will be returned.
val actionBarHeight = TypedValue.complexToDimensionPixelSize(actionBarTv.data, resources.displayMetrics)
.takeIf { resolvedActionBarSize && headerConfig?.mIsHidden != true }
.takeIf { resolvedActionBarSize && headerConfig?.isHeaderHidden != true }
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0

val statusBarHeight = context.resources.getIdentifier("status_bar_height", "dimen", "android")
Expand Down
Loading

0 comments on commit fad311a

Please sign in to comment.