Skip to content

Commit

Permalink
chore: update ktlint (#596)
Browse files Browse the repository at this point in the history
## 📜 Description

Updated `ktlint` to latest `1.3.1` version.
 
## 💡 Motivation and Context

Updated `ktlint` to latest `1.3.1` version and formatted the code
according to new rules.

There was a conflict between `detekt` and `ktlint` (max-len 120 vs 140).
To fix that I added `.editorconfig` where I overwrote default ktlint
config and specified 120 characters as max-len.

## 📢 Changelog

<!-- High level overview of important changes -->
<!-- For example: fixed status bar manipulation; added new types
declarations; -->
<!-- If your changes don't affect one of platform/language below - then
remove this platform/language -->

### Android

- apply new formatting to the code;

### JS

- added `.editorconfig` to npmignore;

### CI

- updated `ktlint` to `1.3.1`

## 🤔 How Has This Been Tested?

Tested on CI.

## 📝 Checklist

- [x] CI successfully passed
- [x] I added new mocks and corresponding unit-tests if library API was
changed
  • Loading branch information
kirillzyusko authored Sep 27, 2024
1 parent 7f13c90 commit 1d43a32
Show file tree
Hide file tree
Showing 44 changed files with 760 additions and 549 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/verify-android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- uses: actions/checkout@v4
- uses: touchlab-lab/[email protected]
with:
ktlint_version: 0.48.0
ktlint_version: 1.3.1
- run: ktlint "android/src/**/*.kt"
android-lint:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions android/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[*.{kt,kts}]
max_line_length = 120
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.reactnativekeyboardcontroller
import com.facebook.react.bridge.ReactApplicationContext
import com.reactnativekeyboardcontroller.modules.KeyboardControllerModuleImpl

class KeyboardControllerModule(mReactContext: ReactApplicationContext) : NativeKeyboardControllerSpec(mReactContext) {
class KeyboardControllerModule(
mReactContext: ReactApplicationContext,
) : NativeKeyboardControllerSpec(mReactContext) {
private val module = KeyboardControllerModuleImpl(mReactContext)

override fun getName(): String = KeyboardControllerModuleImpl.NAME
Expand All @@ -25,10 +27,10 @@ class KeyboardControllerModule(mReactContext: ReactApplicationContext) : NativeK
}

override fun addListener(eventName: String?) {
/* Required for RN built-in Event Emitter Calls. */
// Required for RN built-in Event Emitter Calls.
}

override fun removeListeners(count: Double) {
/* Required for RN built-in Event Emitter Calls. */
// Required for RN built-in Event Emitter Calls.
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,37 @@ import com.facebook.react.views.view.ReactViewManager
import com.reactnativekeyboardcontroller.managers.KeyboardControllerViewManagerImpl
import com.reactnativekeyboardcontroller.views.EdgeToEdgeReactViewGroup

class KeyboardControllerViewManager(mReactContext: ReactApplicationContext) :
ReactViewManager(),
class KeyboardControllerViewManager(
mReactContext: ReactApplicationContext,
) : ReactViewManager(),
KeyboardControllerViewManagerInterface<ReactViewGroup> {
private val manager = KeyboardControllerViewManagerImpl(mReactContext)
private val mDelegate = KeyboardControllerViewManagerDelegate(this)

override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> {
return mDelegate
}
override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> = mDelegate

override fun getName(): String = KeyboardControllerViewManagerImpl.NAME

override fun createViewInstance(context: ThemedReactContext): ReactViewGroup {
return manager.createViewInstance(context)
}
override fun createViewInstance(context: ThemedReactContext): ReactViewGroup = manager.createViewInstance(context)

@ReactProp(name = "statusBarTranslucent")
override fun setStatusBarTranslucent(view: ReactViewGroup, value: Boolean) {
return manager.setStatusBarTranslucent(view as EdgeToEdgeReactViewGroup, value)
}
override fun setStatusBarTranslucent(
view: ReactViewGroup,
value: Boolean,
) = manager.setStatusBarTranslucent(view as EdgeToEdgeReactViewGroup, value)

@ReactProp(name = "navigationBarTranslucent")
override fun setNavigationBarTranslucent(view: ReactViewGroup, value: Boolean) {
return manager.setNavigationBarTranslucent(view as EdgeToEdgeReactViewGroup, value)
}
override fun setNavigationBarTranslucent(
view: ReactViewGroup,
value: Boolean,
) = manager.setNavigationBarTranslucent(view as EdgeToEdgeReactViewGroup, value)

@ReactProp(name = "enabled")
override fun setEnabled(view: ReactViewGroup, value: Boolean) {
return manager.setEnabled(view as EdgeToEdgeReactViewGroup, value)
}
override fun setEnabled(
view: ReactViewGroup,
value: Boolean,
) = manager.setEnabled(view as EdgeToEdgeReactViewGroup, value)

override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> {
return manager.getExportedCustomDirectEventTypeConstants()
}
override fun getExportedCustomDirectEventTypeConstants(): MutableMap<String, Any> =
manager.getExportedCustomDirectEventTypeConstants()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,49 @@ import com.facebook.react.views.view.ReactViewManager
import com.reactnativekeyboardcontroller.managers.KeyboardGestureAreaViewManagerImpl
import com.reactnativekeyboardcontroller.views.KeyboardGestureAreaReactViewGroup

class KeyboardGestureAreaViewManager(mReactContext: ReactApplicationContext) :
ReactViewManager(),
class KeyboardGestureAreaViewManager(
mReactContext: ReactApplicationContext,
) : ReactViewManager(),
KeyboardGestureAreaManagerInterface<ReactViewGroup> {
private val manager = KeyboardGestureAreaViewManagerImpl(mReactContext)
private val mDelegate = KeyboardGestureAreaManagerDelegate(this)

override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> {
return mDelegate
}
override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> = mDelegate

override fun getName(): String = KeyboardGestureAreaViewManagerImpl.NAME

override fun createViewInstance(context: ThemedReactContext): KeyboardGestureAreaReactViewGroup {
return manager.createViewInstance(context)
}
override fun createViewInstance(context: ThemedReactContext): KeyboardGestureAreaReactViewGroup =
manager.createViewInstance(context)

@ReactProp(name = "offset")
override fun setOffset(view: ReactViewGroup, value: Double) {
override fun setOffset(
view: ReactViewGroup,
value: Double,
) {
manager.setOffset(view as KeyboardGestureAreaReactViewGroup, value)
}

@ReactProp(name = "interpolator")
override fun setInterpolator(view: ReactViewGroup, value: String?) {
override fun setInterpolator(
view: ReactViewGroup,
value: String?,
) {
manager.setInterpolator(view as KeyboardGestureAreaReactViewGroup, value ?: "linear")
}

@ReactProp(name = "showOnSwipeUp")
override fun setShowOnSwipeUp(view: ReactViewGroup, value: Boolean) {
override fun setShowOnSwipeUp(
view: ReactViewGroup,
value: Boolean,
) {
manager.setScrollKeyboardOnScreenWhenNotVisible(view as KeyboardGestureAreaReactViewGroup, value)
}

@ReactProp(name = "enableSwipeToDismiss")
override fun setEnableSwipeToDismiss(view: ReactViewGroup?, value: Boolean) {
override fun setEnableSwipeToDismiss(
view: ReactViewGroup?,
value: Boolean,
) {
manager.setScrollKeyboardOffScreenWhenVisible(view as KeyboardGestureAreaReactViewGroup, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ import com.reactnativekeyboardcontroller.managers.OverKeyboardViewManagerImpl
import com.reactnativekeyboardcontroller.views.overlay.OverKeyboardHostShadowNode
import com.reactnativekeyboardcontroller.views.overlay.OverKeyboardHostView

class OverKeyboardViewManager(mReactContext: ReactApplicationContext) :
ReactViewManager(),
class OverKeyboardViewManager(
mReactContext: ReactApplicationContext,
) : ReactViewManager(),
OverKeyboardViewManagerInterface<ReactViewGroup> {
private val manager = OverKeyboardViewManagerImpl(mReactContext)
private val mDelegate = OverKeyboardViewManagerDelegate(this)

override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> {
return mDelegate
}
override fun getDelegate(): ViewManagerDelegate<ReactViewGroup?> = mDelegate

override fun getName(): String = OverKeyboardViewManagerImpl.NAME

override fun createViewInstance(context: ThemedReactContext): OverKeyboardHostView {
return manager.createViewInstance(context)
}
override fun createViewInstance(context: ThemedReactContext): OverKeyboardHostView =
manager.createViewInstance(context)

override fun createShadowNodeInstance(): LayoutShadowNode = OverKeyboardHostShadowNode()

override fun getShadowNodeClass(): Class<out LayoutShadowNode> =
OverKeyboardHostShadowNode::class.java
override fun getShadowNodeClass(): Class<out LayoutShadowNode> = OverKeyboardHostShadowNode::class.java

@ReactProp(name = "visible")
override fun setVisible(view: ReactViewGroup?, value: Boolean) {
override fun setVisible(
view: ReactViewGroup?,
value: Boolean,
) {
manager.setVisible(view as OverKeyboardHostView, value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ package com.reactnativekeyboardcontroller
import com.facebook.react.bridge.ReactApplicationContext
import com.reactnativekeyboardcontroller.modules.StatusBarManagerCompatModuleImpl

class StatusBarManagerCompatModule(mReactContext: ReactApplicationContext) :
NativeStatusBarManagerCompatSpec(mReactContext) {
class StatusBarManagerCompatModule(
mReactContext: ReactApplicationContext,
) : NativeStatusBarManagerCompatSpec(mReactContext) {
private val module = StatusBarManagerCompatModuleImpl(mReactContext)

override fun getName(): String = StatusBarManagerCompatModuleImpl.NAME
Expand All @@ -13,7 +14,10 @@ class StatusBarManagerCompatModule(mReactContext: ReactApplicationContext) :
module.setHidden(hidden)
}

override fun setColor(color: Double, animated: Boolean) {
override fun setColor(
color: Double,
animated: Boolean,
) {
module.setColor(color.toInt(), animated)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import com.reactnativekeyboardcontroller.modules.StatusBarManagerCompatModuleImp

class KeyboardControllerPackage : TurboReactPackage() {
@Nullable
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
return when (name) {
override fun getModule(
name: String,
reactContext: ReactApplicationContext,
): NativeModule? =
when (name) {
KeyboardControllerModuleImpl.NAME -> {
KeyboardControllerModule(reactContext)
}
Expand All @@ -24,40 +27,39 @@ class KeyboardControllerPackage : TurboReactPackage() {
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[KeyboardControllerModuleImpl.NAME] = ReactModuleInfo(
KeyboardControllerModuleImpl.NAME,
KeyboardControllerModuleImpl.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule, // isTurboModule
)
moduleInfos[StatusBarManagerCompatModuleImpl.NAME] = ReactModuleInfo(
StatusBarManagerCompatModuleImpl.NAME,
StatusBarManagerCompatModuleImpl.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule, // isTurboModule
)
moduleInfos[KeyboardControllerModuleImpl.NAME] =
ReactModuleInfo(
KeyboardControllerModuleImpl.NAME,
KeyboardControllerModuleImpl.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule, // isTurboModule
)
moduleInfos[StatusBarManagerCompatModuleImpl.NAME] =
ReactModuleInfo(
StatusBarManagerCompatModuleImpl.NAME,
StatusBarManagerCompatModuleImpl.NAME,
false, // canOverrideExistingModule
false, // needsEagerInit
true, // hasConstants
false, // isCxxModule
isTurboModule, // isTurboModule
)
moduleInfos
}
}

override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
return listOf(
override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> =
listOf(
KeyboardControllerViewManager(reactContext),
KeyboardGestureAreaViewManager(reactContext),
OverKeyboardViewManager(reactContext),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,20 @@ class FocusedInputLayoutChangedEvent(
// All events for a given view can be coalesced
override fun getCoalescingKey(): Short = 0

override fun getEventData(): WritableMap? = Arguments.createMap().apply {
putInt("target", event.target)
putInt("parentScrollViewTarget", event.parentScrollViewTarget)
putMap(
"layout",
Arguments.createMap().apply {
putDouble("x", event.x)
putDouble("y", event.y)
putDouble("width", event.width)
putDouble("height", event.height)
putDouble("absoluteX", event.absoluteX)
putDouble("absoluteY", event.absoluteY)
},
)
}
override fun getEventData(): WritableMap? =
Arguments.createMap().apply {
putInt("target", event.target)
putInt("parentScrollViewTarget", event.parentScrollViewTarget)
putMap(
"layout",
Arguments.createMap().apply {
putDouble("x", event.x)
putDouble("y", event.y)
putDouble("width", event.width)
putDouble("height", event.height)
putDouble("absoluteX", event.absoluteX)
putDouble("absoluteY", event.absoluteY)
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,29 @@ class FocusedInputSelectionChangedEvent(
// All events for a given view can be coalesced
override fun getCoalescingKey(): Short = 0

override fun getEventData(): WritableMap? = Arguments.createMap().apply {
putInt("target", event.target)
putMap(
"selection",
Arguments.createMap().apply {
putMap(
"start",
Arguments.createMap().apply {
putDouble("x", event.startX)
putDouble("y", event.startY)
putInt("position", event.start)
},
)
putMap(
"end",
Arguments.createMap().apply {
putDouble("x", event.endX)
putDouble("y", event.endY)
putInt("position", event.end)
},
)
},
)
}
override fun getEventData(): WritableMap? =
Arguments.createMap().apply {
putInt("target", event.target)
putMap(
"selection",
Arguments.createMap().apply {
putMap(
"start",
Arguments.createMap().apply {
putDouble("x", event.startX)
putDouble("y", event.startY)
putInt("position", event.start)
},
)
putMap(
"end",
Arguments.createMap().apply {
putDouble("x", event.endX)
putDouble("y", event.endY)
putInt("position", event.end)
},
)
},
)
}
}
Loading

0 comments on commit 1d43a32

Please sign in to comment.