Skip to content

Commit

Permalink
chore(Android): update spotless & ktlint (#2189)
Browse files Browse the repository at this point in the history
## Description

Encountered some errors (seems they were looking for old CMake version
(3.10.2)) & decided to bump these deps as they are long overdue.

## Changes

Ktlint: 0.43 -> 1.1.1
spotless 6.11 -> 6.22

## Checklist

- [ ] Ensured that CI passes
  • Loading branch information
kkafar authored and alduzy committed Jun 28, 2024
1 parent 8717c11 commit c1373d6
Show file tree
Hide file tree
Showing 49 changed files with 1,170 additions and 563 deletions.
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ buildscript {
dependencies {
classpath('com.android.tools.build:gradle:4.2.2')
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${safeExtGet('kotlinVersion', rnsDefaultKotlinVersion)}"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.11.0"
classpath "com.diffplug.spotless:spotless-plugin-gradle:6.25.0"
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/spotless.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ apply plugin: 'com.diffplug.spotless'
spotless {
kotlin {
target 'src/**/*.kt'
ktlint("0.43.0")
ktlint("1.3.0")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,31 @@ import com.facebook.react.uimanager.FabricViewStateManager
import com.facebook.react.uimanager.PixelUtil
import kotlin.math.abs

abstract class FabricEnabledViewGroup constructor(context: ReactContext?) : ViewGroup(context), FabricViewStateManager.HasFabricViewStateManager {
abstract class FabricEnabledViewGroup constructor(
context: ReactContext?,
) : ViewGroup(context),
FabricViewStateManager.HasFabricViewStateManager {
private val mFabricViewStateManager: FabricViewStateManager = FabricViewStateManager()

private var lastSetWidth = 0f
private var lastSetHeight = 0f

override fun getFabricViewStateManager(): FabricViewStateManager {
return mFabricViewStateManager
}
override fun getFabricViewStateManager(): FabricViewStateManager = mFabricViewStateManager

protected fun updateScreenSizeFabric(width: Int, height: Int, headerHeight: Double) {
protected fun updateScreenSizeFabric(
width: Int,
height: Int,
headerHeight: Double,
) {
updateState(width, height, headerHeight)
}

@UiThread
fun updateState(width: Int, height: Int, headerHeight: Double) {
fun updateState(
width: Int,
height: Int,
headerHeight: Double,
) {
val realWidth: Float = PixelUtil.toDIPFromPixel(width.toFloat())
val realHeight: Float = PixelUtil.toDIPFromPixel(height.toFloat())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@ import androidx.appcompat.widget.SearchView
import androidx.fragment.app.Fragment

@SuppressLint("ViewConstructor") // Only we construct this view, it is never inflated.
class CustomSearchView(context: Context, fragment: Fragment) : SearchView(context) {
class CustomSearchView(
context: Context,
fragment: Fragment,
) : SearchView(context) {
/*
CustomSearchView uses some variables from SearchView. They are listed below with links to documentation
isIconified - https://developer.android.com/reference/android/widget/SearchView#setIconified(boolean)
maxWidth - https://developer.android.com/reference/android/widget/SearchView#setMaxWidth(int)
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 onCloseListener: OnCloseListener? = null
private var onSearchClickedListener: OnClickListener? = null

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@ import androidx.appcompat.widget.Toolbar

// This class is used to store config closer to search bar
@SuppressLint("ViewConstructor") // Only we construct this view, it is never inflated.
open class CustomToolbar(context: Context, val config: ScreenStackHeaderConfig) : Toolbar(context)
open class CustomToolbar(
context: Context,
val config: ScreenStackHeaderConfig,
) : Toolbar(context)
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment

class FragmentBackPressOverrider(
private val fragment: Fragment,
private val onBackPressedCallback: OnBackPressedCallback
private val onBackPressedCallback: OnBackPressedCallback,
) {
private var isCallbackAdded: Boolean = false
var overrideBackAction: Boolean = true
Expand All @@ -14,7 +14,7 @@ class FragmentBackPressOverrider(
if (!isCallbackAdded && overrideBackAction) {
fragment.activity?.onBackPressedDispatcher?.addCallback(
fragment,
onBackPressedCallback
onBackPressedCallback,
)
isCallbackAdded = true
}
Expand Down
35 changes: 19 additions & 16 deletions android/src/main/java/com/swmansion/rnscreens/LifecycleHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@ import androidx.lifecycle.LifecycleObserver

class LifecycleHelper {
private val mViewToLifecycleMap: MutableMap<View, Lifecycle> = HashMap()
private val mRegisterOnLayoutChange: View.OnLayoutChangeListener = object : View.OnLayoutChangeListener {
override fun onLayoutChange(
view: View,
i: Int,
i1: Int,
i2: Int,
i3: Int,
i4: Int,
i5: Int,
i6: Int,
i7: Int
) {
registerViewWithLifecycleOwner(view)
view.removeOnLayoutChangeListener(this)
private val mRegisterOnLayoutChange: View.OnLayoutChangeListener =
object : View.OnLayoutChangeListener {
override fun onLayoutChange(
view: View,
i: Int,
i1: Int,
i2: Int,
i3: Int,
i4: Int,
i5: Int,
i6: Int,
i7: Int,
) {
registerViewWithLifecycleOwner(view)
view.removeOnLayoutChangeListener(this)
}
}
}

private fun registerViewWithLifecycleOwner(view: View) {
val parent = findNearestScreenFragmentAncestor(view)
Expand Down Expand Up @@ -54,7 +55,9 @@ class LifecycleHelper {
}
return if (parent != null) {
(parent as Screen).fragment
} else null
} else {
null
}
}
}
}
34 changes: 16 additions & 18 deletions android/src/main/java/com/swmansion/rnscreens/RNScreensPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@ import com.facebook.react.module.model.ReactModuleInfoProvider
import com.facebook.react.uimanager.ViewManager
import com.swmansion.rnscreens.utils.ScreenDummyLayoutHelper


@ReactModuleList(
nativeModules = [
ScreensModule::class
]
ScreensModule::class,
],
)
class RNScreensPackage : TurboReactPackage() {
// We just retain it here. This object helps us tackle jumping content when using native header.
// See: https://github.com/software-mansion/react-native-screens/pull/2169
private var screenDummyLayoutHelper: ScreenDummyLayoutHelper? = null


override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
// This is the earliest we lay our hands on react context.
// Moreover this is called before FabricUIManger has finished initializing, not to mention
Expand All @@ -36,36 +34,36 @@ class RNScreensPackage : TurboReactPackage() {
ScreenStackViewManager(),
ScreenStackHeaderConfigViewManager(),
ScreenStackHeaderSubviewManager(),
SearchBarManager()
SearchBarManager(),
)
}

override fun getModule(
s: String,
reactApplicationContext: ReactApplicationContext
reactApplicationContext: ReactApplicationContext,
): NativeModule? {
when (s) {
ScreensModule.NAME -> return ScreensModule(reactApplicationContext)
}
return null
}

override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
return ReactModuleInfoProvider {
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider =
ReactModuleInfoProvider {
val moduleInfos: MutableMap<String, ReactModuleInfo> = HashMap()
val isTurboModule = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
moduleInfos[ScreensModule.NAME] = ReactModuleInfo(
ScreensModule.NAME,
ScreensModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule
)
moduleInfos[ScreensModule.NAME] =
ReactModuleInfo(
ScreensModule.NAME,
ScreensModule.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule,
)
moduleInfos
}
}

companion object {
const val TAG = "RNScreensPackage"
Expand Down
Loading

0 comments on commit c1373d6

Please sign in to comment.