Skip to content

Commit

Permalink
Various iOS styling fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownJoe796 committed Dec 10, 2024
1 parent 8ded4b4 commit 2f19aea
Show file tree
Hide file tree
Showing 15 changed files with 131 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "188D8B942B2B9CB400732A2E"
BuildableName = "KiteUI Example App.app"
BlueprintName = "KiteUI Example App"
ReferencedContainer = "container:KiteUI Example App.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "188D8B942B2B9CB400732A2E"
BuildableName = "KiteUI Example App.app"
BlueprintName = "KiteUI Example App"
ReferencedContainer = "container:KiteUI Example App.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"info": { "version": 1, "author": "xcode" },
"images": [
{
"filename": "graph_126.png",
"scale": "1x",
"idiom": "universal"
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import com.lightningkite.kiteui.navigation.mainScreenNavigator
import com.lightningkite.kiteui.reactive.*
import com.lightningkite.kiteui.views.*
import com.lightningkite.kiteui.views.l2.*
import com.lightningkite.mppexampleapp.internal.RootScreen
import kotlin.math.absoluteValue
import kotlin.time.Duration.Companion.seconds

Expand All @@ -22,6 +23,7 @@ fun ViewWriter.app(navigator: ScreenNavigator, dialog: ScreenNavigator) {
::navItems {
listOf(
NavLink(title = { "Home" }, icon = { Icon.home }) { { HomeScreen() } },
NavLink(title = { "Internal" }, icon = { Icon.home }) { { RootScreen } },
NavLink(title = { "Documentation" }, icon = { Icon.list }) { { DocSearchScreen } },
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.lightningkite.mppexampleapp

import com.lightningkite.kiteui.models.remMultiplier
import com.lightningkite.kiteui.navigation.ScreenNavigator
import com.lightningkite.kiteui.views.setup
import platform.UIKit.UIViewController

fun root(viewController: UIViewController) {
remMultiplier = 1.0
viewController.setup(appTheme) { app(ScreenNavigator { AutoRoutes }, ScreenNavigator { AutoRoutes }) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ actual class Code actual constructor(context: RContext) : RView(context) {
}

override fun applyForeground(theme: Theme) {
fontAndStyle = theme.font
actualNative.foreground = theme.foreground
fontAndStyle = theme.font

//
// sizeConstraints = SizeConstraints(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ actual typealias DimensionRaw = Double
@Suppress("NOTHING_TO_INLINE") actual inline val Int.px: Dimension
get() = Dimension(this.toDouble() / UIScreen.mainScreen.scale)

var remMultiplier: Double = 0.75
var remMultiplier: Double = 1.0

@Suppress("NOTHING_TO_INLINE") actual inline val Int.rem: Dimension
get() = Dimension(this.toDouble() * UIFont.systemFontSize * remMultiplier)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import com.lightningkite.kiteui.reactive.AppState
import com.lightningkite.kiteui.views.direct.WrapperView
import kotlinx.cinterop.useContents
import platform.CoreGraphics.CGPointMake
import platform.CoreGraphics.CGRectMake
import platform.CoreGraphics.CGSizeMake
import platform.Foundation.NSNumber
import platform.Foundation.numberWithFloat
import platform.QuartzCore.CATransaction
import platform.QuartzCore.kCAGradientLayerAxial
import platform.QuartzCore.kCAGradientLayerRadial
import platform.UIKit.UIColor
import platform.UIKit.UIScrollView
import platform.UIKit.UIView
import kotlin.experimental.ExperimentalNativeApi
import kotlin.math.PI
Expand Down Expand Up @@ -222,7 +224,10 @@ actual abstract class RView actual constructor(context: RContext) : RViewHelper(
parentSpacing = this@RView.parentSpacing.value
desiredCornerRadius = theme.cornerRadii

matchParentSize("insert")
val bounds = this@RView.native.layerSize()

frame = bounds
refreshCorners()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ class LinearLayout : UIView(CGRectZero.readValue()), UIViewWithSizeOverridesProt
val UIView.secondaryAlign get() = if (horizontal) extensionVerticalAlign else extensionHorizontalAlign

override fun sizeThatFits(size: CValue<CGSize>): CValue<CGSize> {
if(subviews.any { it == viewDebugTarget?.native }) {
println("parent sizeThatFits: ${size.useContents { "$width x $height" }}")
}
val sizeLocal = size.local
val measuredSize = Size()

Expand Down Expand Up @@ -212,6 +215,9 @@ class LinearLayout : UIView(CGRectZero.readValue()), UIViewWithSizeOverridesProt

var lastLaidOutSize: Size? = null
override fun layoutSubviews() {
if(subviews.any { it == viewDebugTarget?.native }) {
println("parent layoutSubviews: ${bounds.useContents { "${size.width} x ${size.height}" }}")
}
val mySize = bounds.useContents { size.local }
if (lastLaidOutSize == mySize) return
var t = PerformanceInfo.trace("layoutLinear")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ actual class TextView actual constructor(context: RContext) : RView(context) {
}

override fun applyForeground(theme: Theme) {
fontAndStyle = theme.font
native.foreground = theme.foreground
fontAndStyle = theme.font

//
// sizeConstraints = SizeConstraints(
Expand Down Expand Up @@ -165,12 +165,3 @@ fun preferredScaleFactor() = if (ENABLE_DYNAMIC_TYPE) {
} else {
1.0
}

fun UILabel.updateFont() {
val textSize = extensionTextSize ?: return
val alignment = textAlignment
font = extensionFontAndStyle?.let {
it.font.get(textSize * preferredScaleFactor(), it.weight.toUIFontWeight(), it.italic)
} ?: UIFont.systemFontOfSize(textSize)
textAlignment = alignment
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class UILabelWithGradient : UIView(CGRectZero.readValue()) {
)
}
return label.sizeThatFits(smallerSize).useContents {
if(com.lightningkite.kiteui.viewDebugTarget?.native == this@UILabelWithGradient)
println("Size that fits on text: $width, $height")
CGSizeMake(
width = width + padding * 2,
height = height.coerceAtLeast(label.font.lineHeight) + padding * 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import com.lightningkite.kiteui.reactive.invoke
import com.lightningkite.kiteui.reactive.reactiveScope
import com.lightningkite.kiteui.views.*
import kotlinx.cinterop.*
import platform.QuartzCore.CALayer
import platform.CoreGraphics.CGRectMake
import platform.UIKit.UILongPressGestureRecognizer
import platform.UIKit.UITapGestureRecognizer
import platform.darwin.NSObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ fun UIView.sizeThatFits2(
it.maxHeight?.let { h = h.coerceAtMost(it.value) }
it.minWidth?.let { w = w.coerceAtLeast(it.value) }
it.minHeight?.let { h = h.coerceAtLeast(it.value) }
it.width?.let { w = it.value }
it.height?.let { h = it.value }
it.width?.let { w = it.value.coerceAtMost(w) }
it.height?.let { h = it.value.coerceAtMost(h) }
CGSizeMake(w, h)
} ?: size
val measured = when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ import com.lightningkite.kiteui.models.*
import com.lightningkite.kiteui.objc.toObjcId
import com.lightningkite.kiteui.reactive.await
import com.lightningkite.kiteui.reactive.reactiveScope
import com.lightningkite.kiteui.views.RView
import kotlinx.cinterop.BetaInteropApi
import kotlinx.cinterop.CValue
import kotlinx.cinterop.ExperimentalForeignApi
import kotlinx.cinterop.useContents
import platform.CoreGraphics.*
import platform.QuartzCore.*
import platform.UIKit.UIColor
import platform.UIKit.UIImageView
import platform.UIKit.UIView
import platform.UIKit.UIScrollView
import kotlin.math.min
import kotlin.time.DurationUnit
import platform.Foundation.*
Expand All @@ -24,14 +27,6 @@ fun Color.toUiColor(): UIColor = UIColor(
)



@Suppress("NOTHING_TO_INLINE")
internal inline fun CALayer.matchParentSize(context: String) {
superlayer?.bounds?.let {
frame = it
}
}

@Suppress("NOTHING_TO_INLINE")
internal inline fun UIView.layoutSubviewsAndLayers() {
// Fixes a really cursed crash where "this" is null due to GC interactions
Expand All @@ -42,32 +37,50 @@ internal inline fun UIView.layoutSubviewsAndLayers() {
}
}

internal fun UIView.layerSize(): CValue<CGRect> {
val n = this
val bounds = if(n is UIScrollView) n.contentSize.useContents {
val cs = this
n.bounds.useContents {
val b = this
CGRectMake(0.0, 0.0, cs.width + b.size.width, cs.height + b.size.height)
}
} else n.bounds
return bounds
}

internal fun UIView.layoutLayers() {
val bounds = layerSize()
layer?.sublayers?.forEach {
it as CALayer
if(it is CAGradientLayerResizing) {
it.matchParentSize("layoutSubviewsAndLayers")
if (it is CAGradientLayerResizing) {
it.frame = bounds
it.refreshCorners()
}
}
}

internal fun UIView.layoutLayers(parentSpacing: Double) {
val bounds = layerSize()
layer?.sublayers?.forEach {
it as CALayer
if(it is CAGradientLayerResizing) {
if (it is CAGradientLayerResizing) {
it.parentSpacing = parentSpacing
it.matchParentSize("layoutSubviewsAndLayers")
it.frame = bounds
it.refreshCorners()
}
}
}


class CAGradientLayerResizing: CAGradientLayer {
class CAGradientLayerResizing : CAGradientLayer {

@OverrideInit constructor():super()
@OverrideInit constructor(coder: platform.Foundation.NSCoder):super(coder)
@OverrideInit constructor(layer: kotlin.Any):super(layer)
@OverrideInit
constructor() : super()
@OverrideInit
constructor(coder: platform.Foundation.NSCoder) : super(coder)
@OverrideInit
constructor(layer: kotlin.Any) : super(layer)

private var backgroundMask: CALayer? = null

Expand Down Expand Up @@ -99,7 +112,7 @@ class CAGradientLayerResizing: CAGradientLayer {
}

fun refreshCorners() {
val v = when(val d = desiredCornerRadius) {
val v = when (val d = desiredCornerRadius) {
is CornerRadii.Constant -> d.value.value.coerceAtMost(parentSpacing).coerceAtMost(bounds.useContents { min(size.width, size.height) / 2 })
is CornerRadii.ForceConstant -> d.value.value.coerceAtMost(bounds.useContents { min(size.width, size.height) / 2 })
is CornerRadii.RatioOfSize -> d.ratio * bounds.useContents { min(size.width, size.height) }
Expand Down

0 comments on commit 2f19aea

Please sign in to comment.