Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(Android): update spotless & ktlint #2053

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Example/.detoxrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
type: 'android.apk',
binaryPath: 'android/app/build/outputs/apk/release/app-release.apk',
build:
'cd android && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release -PreactNativeArchitectures=x86_64 && cd ..',
'cd android && ./gradlew -v && ./gradlew assembleRelease assembleAndroidTest -DtestBuildType=release -PreactNativeArchitectures=x86_64 --warning-mode all && cd ..',
},
},
devices: {
Expand Down
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.22.0"
}
}

Expand Down
2 changes: 1 addition & 1 deletion android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip
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.2.1")
trimTrailingWhitespace()
indentWithSpaces()
endWithNewline()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,52 @@ 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 {
private val mFabricViewStateManager: FabricViewStateManager = FabricViewStateManager()

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

override fun getFabricViewStateManager(): FabricViewStateManager {
return mFabricViewStateManager
}

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

@UiThread
fun updateState(width: Int, height: Int) {
val realWidth: Float = PixelUtil.toDIPFromPixel(width.toFloat())
val realHeight: Float = PixelUtil.toDIPFromPixel(height.toFloat())
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
}

// Check incoming state values. If they're already the correct value, return early to prevent
// infinite UpdateState/SetState loop.
val delta = 0.9f
if (abs(lastSetWidth - realWidth) < delta &&
abs(lastSetHeight - realHeight) < delta
protected fun updateScreenSizeFabric(
width: Int,
height: Int,
) {
return
updateState(width, height)
}

lastSetWidth = realWidth
lastSetHeight = realHeight

mFabricViewStateManager.setState {
val map: WritableMap = WritableNativeMap()
map.putDouble("frameWidth", realWidth.toDouble())
map.putDouble("frameHeight", realHeight.toDouble())
map
@UiThread
fun updateState(
width: Int,
height: Int,
) {
val realWidth: Float = PixelUtil.toDIPFromPixel(width.toFloat())
val realHeight: Float = PixelUtil.toDIPFromPixel(height.toFloat())

// Check incoming state values. If they're already the correct value, return early to prevent
// infinite UpdateState/SetState loop.
val delta = 0.9f
if (abs(lastSetWidth - realWidth) < delta &&
abs(lastSetHeight - realHeight) < delta
) {
return
}

lastSetWidth = realWidth
lastSetHeight = realHeight

mFabricViewStateManager.setState {
val map: WritableMap = WritableNativeMap()
map.putDouble("frameWidth", realWidth.toDouble())
map.putDouble("frameHeight", realHeight.toDouble())
map
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class CustomSearchView(context: Context, fragment: Fragment) : SearchView(contex
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 @@ -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
}
}
}
}
27 changes: 14 additions & 13 deletions android/src/main/java/com/swmansion/rnscreens/RNScreensPackage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.facebook.react.uimanager.ViewManager

@ReactModuleList(
nativeModules = [
ScreensModule::class
]
ScreensModule::class,
],
)
class RNScreensPackage : TurboReactPackage() {
override fun createViewManagers(reactContext: ReactApplicationContext) =
Expand All @@ -21,12 +21,12 @@ 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)
Expand All @@ -38,15 +38,16 @@ class RNScreensPackage : TurboReactPackage() {
return 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
}
}
Expand Down
Loading
Loading