Skip to content

Commit

Permalink
Apply ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
kkafar committed Jun 17, 2024
1 parent 29f1f02 commit 2da47f6
Show file tree
Hide file tree
Showing 45 changed files with 1,039 additions and 480 deletions.
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
}
}
}
}
32 changes: 16 additions & 16 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 @@ -22,33 +22,33 @@ 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
}
}
}
107 changes: 74 additions & 33 deletions android/src/main/java/com/swmansion/rnscreens/Screen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import com.facebook.react.uimanager.UIManagerModule
import com.swmansion.rnscreens.events.HeaderHeightChangeEvent

@SuppressLint("ViewConstructor") // Only we construct this view, it is never inflated.
class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
class Screen(
context: ReactContext?,
) : FabricEnabledViewGroup(context) {
val fragment: Fragment?
get() = fragmentWrapper?.fragment

Expand Down Expand Up @@ -60,7 +62,13 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
// ignore restoring instance state too as we are not saving anything anyways.
}

override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {
override fun onLayout(
changed: Boolean,
l: Int,
t: Int,
r: Int,
b: Int,
) {
if (container is ScreenStack && changed) {
val width = r - l
val height = b - t
Expand All @@ -77,7 +85,10 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
}
}

private fun updateScreenSizePaper(width: Int, height: Int) {
private fun updateScreenSizePaper(
width: Int,
height: Int,
) {
val reactContext = context as ReactContext
reactContext.runOnNativeModulesQueueThread(
object : GuardedRunnable(reactContext.exceptionHandler) {
Expand All @@ -86,7 +97,8 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
.getNativeModule(UIManagerModule::class.java)
?.updateNodeSize(id, width, height)
}
})
},
)
}

val headerConfig: ScreenStackHeaderConfig?
Expand All @@ -108,7 +120,7 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
}
super.setLayerType(
if (transitioning && !isWebViewInScreen) LAYER_TYPE_HARDWARE else LAYER_TYPE_NONE,
null
null,
)
}

Expand All @@ -126,7 +138,10 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
return false
}

override fun setLayerType(layerType: Int, paint: Paint?) {
override fun setLayerType(
layerType: Int,
paint: Paint?,
) {
// ignore - layer type is controlled by `transitioning` prop
}

Expand All @@ -144,16 +159,17 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
return
}
ScreenWindowTraits.applyDidSetOrientation()
this.screenOrientation = when (screenOrientation) {
"all" -> ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
"portrait" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
"portrait_up" -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
"portrait_down" -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
"landscape" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
"landscape_left" -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
"landscape_right" -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
else -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}
this.screenOrientation =
when (screenOrientation) {
"all" -> ActivityInfo.SCREEN_ORIENTATION_FULL_SENSOR
"portrait" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
"portrait_up" -> ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
"portrait_down" -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT
"landscape" -> ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
"landscape_left" -> ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE
"landscape_right" -> ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
else -> ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
}

fragmentWrapper?.let { ScreenWindowTraits.setOrientation(this, it.tryGetActivity()) }
}
Expand Down Expand Up @@ -193,7 +209,7 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {
ScreenWindowTraits.setTranslucent(
this,
it.tryGetActivity(),
it.tryGetContext()
it.tryGetContext(),
)
}
}
Expand Down Expand Up @@ -252,44 +268,69 @@ class Screen(context: ReactContext?) : FabricEnabledViewGroup(context) {

// 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?.isHeaderHidden != true && headerConfig?.isHeaderTranslucent != true }
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0

val statusBarHeight = context.resources.getIdentifier("status_bar_height", "dimen", "android")
// Count only status bar when action bar is visible and status bar is not hidden
.takeIf { it > 0 && isStatusBarHidden != true && actionBarHeight > 0 }
?.let { (context.resources::getDimensionPixelSize)(it) }
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() }
?: 0.0
val actionBarHeight =
TypedValue
.complexToDimensionPixelSize(actionBarTv.data, resources.displayMetrics)
.takeIf { resolvedActionBarSize && headerConfig?.isHeaderHidden != true && headerConfig?.isHeaderTranslucent != true }
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() } ?: 0.0

val statusBarHeight =
context.resources
.getIdentifier("status_bar_height", "dimen", "android")
// Count only status bar when action bar is visible and status bar is not hidden
.takeIf { it > 0 && isStatusBarHidden != true && actionBarHeight > 0 }
?.let { (context.resources::getDimensionPixelSize)(it) }
?.let { PixelUtil.toDIPFromPixel(it.toFloat()).toDouble() }
?: 0.0

return actionBarHeight to statusBarHeight
}

private fun notifyHeaderHeightChange(headerHeight: Double) {
val screenContext = context as ReactContext
val surfaceId = UIManagerHelper.getSurfaceId(screenContext)
UIManagerHelper.getEventDispatcherForReactTag(screenContext, id)
UIManagerHelper
.getEventDispatcherForReactTag(screenContext, id)
?.dispatchEvent(HeaderHeightChangeEvent(surfaceId, id, headerHeight))
}

enum class StackPresentation {
PUSH, MODAL, TRANSPARENT_MODAL
PUSH,
MODAL,
TRANSPARENT_MODAL,
}

enum class StackAnimation {
DEFAULT, NONE, FADE, SLIDE_FROM_BOTTOM, SLIDE_FROM_RIGHT, SLIDE_FROM_LEFT, FADE_FROM_BOTTOM, IOS
DEFAULT,
NONE,
FADE,
SLIDE_FROM_BOTTOM,
SLIDE_FROM_RIGHT,
SLIDE_FROM_LEFT,
FADE_FROM_BOTTOM,
IOS,
}

enum class ReplaceAnimation {
PUSH, POP
PUSH,
POP,
}

enum class ActivityState {
INACTIVE, TRANSITIONING_OR_BELOW_TOP, ON_TOP
INACTIVE,
TRANSITIONING_OR_BELOW_TOP,
ON_TOP,
}

enum class WindowTraits {
ORIENTATION, COLOR, STYLE, TRANSLUCENT, HIDDEN, ANIMATED, NAVIGATION_BAR_COLOR, NAVIGATION_BAR_TRANSLUCENT, NAVIGATION_BAR_HIDDEN
ORIENTATION,
COLOR,
STYLE,
TRANSLUCENT,
HIDDEN,
ANIMATED,
NAVIGATION_BAR_COLOR,
NAVIGATION_BAR_TRANSLUCENT,
NAVIGATION_BAR_HIDDEN,
}
}
Loading

0 comments on commit 2da47f6

Please sign in to comment.