SwiftUI:点击TextField时间歇性崩溃



我的一些用户报告说,当他们试图点击自定义样式的文本字段(没有什么特别的)时,自动纠错和自动大写关闭。我不能复制它,他们也不能复制它。似乎有2个特定的文本字段会导致问题,两者都包含在fullscreenCover呈现的更大视图中。崩溃日志没有指向任何具体的东西。下面是崩溃日志:

Thread 0 name:
Thread 0 Crashed:
0   SwiftUI                         0x000000018e0c9154 CGRect.subscript.getter + 140 (Rect.swift:0)
1   SwiftUI                         0x000000018e0c9128 CGRect.subscript.getter + 96 (Rect.swift:0)
2   SwiftUI                         0x000000018d09ca98 $s7SwiftUI16IncrementalStackPA2A01_cD6_StateVyxG0E0RtzrlE5place8children7context5state2inyAA01_C15Layout_ChildrenV_AA01_cK17_PlacementContextVAFzAA01_cK11_PlacementsVztFAA010LazyHStackK033_00B4ADB3... + 304
3   SwiftUI                         0x000000018cfb477c specialized closure #2 in IncrementalChildPlacements.updateValue() + 396 (<compiler-generated>:0)
4   SwiftUI                         0x000000018d105b9c partial apply for closure #1 in _ViewCache.withMutableState<A, B>(type:_:) + 24 (IncrementalLayout.swift:1469)
5   libswiftCore.dylib              0x00000001839275b4 withUnsafePointer<A, B>(to:_:) + 20 (LifetimeManager.swift:144)
6   libswiftCore.dylib              0x0000000183afacac withUnsafeMutablePointer<A, B>(to:_:) + 12
7   SwiftUI                         0x000000018d0c7eb8 _ViewCache.withMutableState<A, B>(type:_:) + 236 (IncrementalLayout.swift:1466)
8   SwiftUI                         0x000000018d1e032c specialized IncrementalChildPlacements.updateValue() + 704
9   SwiftUI                         0x000000018d098808 partial apply for specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init<A>(_:) + 96 (<compiler-generated>:0)
10  AttributeGraph                  0x00000001aa5ae858 AG::Graph::UpdateStack::update() + 512 (ag-closure.h:109)
11  AttributeGraph                  0x00000001aa5ade50 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, unsigned int) + 420 (ag-graph-update.cc:714)
12  AttributeGraph                  0x00000001aa5acc7c AG::Subgraph::update(unsigned int) + 828 (ag-subgraph.cc:734)
13  SwiftUI                         0x000000018cf825f8 ViewGraph.updateOutputs() + 216 (GraphHost.swift:640)
14  SwiftUI                         0x000000018cf8fc98 closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 2200 (ViewGraph.swift:592)
15  SwiftUI                         0x000000018d01be50 ViewRendererHost.render(interval:updateDisplayList:) + 360 (ViewRendererHost.swift:192)
16  SwiftUI                         0x000000018cf83d20 _UIHostingView.displayLinkTimer(timestamp:isAsyncThread:) + 244 (UIHostingView.swift:2109)
17  SwiftUI                         0x000000018cf81eac DisplayLink.displayLinkTimer(_:) + 308 (_UIHostingView.swift:883)
18  SwiftUI                         0x000000018cf83174 @objc DisplayLink.displayLinkTimer(_:) + 52 (<compiler-generated>:0)
19  QuartzCore                      0x000000018add6614 CA::Display::DisplayLink::dispatch_items(unsigned long long, unsigned long long, unsigned long long) + 832 (CADisplay.mm:4507)
20  QuartzCore                      0x000000018ade7698 display_timer_callback(__CFMachPort*, void*, long, void*) + 368 (CADisplayTimer.cpp:219)
21  CoreFoundation                  0x00000001849b1c34 __CFMachPortPerform + 172 (CFMachPort.c:586)
22  CoreFoundation                  0x00000001849ccf04 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 56 (CFRunLoop.c:1981)
23  CoreFoundation                  0x00000001849cea30 __CFRunLoopDoSource1 + 512 (CFRunLoop.c:2120)
24  CoreFoundation                  0x00000001849b258c __CFRunLoopRun + 2324 (CFRunLoop.c:3175)
25  CoreFoundation                  0x00000001849b6b58 CFRunLoopRunSpecific + 584 (CFRunLoop.c:3418)
26  GraphicsServices                0x00000001bf21f984 GSEventRunModal + 160 (GSEvent.c:2196)
27  UIKitCore                       0x000000018bc0d628 -[UIApplication _run] + 868 (UIApplication.m:3754)
28  UIKitCore                       0x000000018bc0d2a0 UIApplicationMain + 312 (UIApplication.m:5344)
29  SwiftUI                         0x000000018d106cfc closure #1 in KitRendererCommon(_:) + 164 (UIKitApp.swift:37)
30  SwiftUI                         0x000000018d07d6a4 runApp<A>(_:) + 140 (<compiler-generated>:0)
31  SwiftUI                         0x000000018d069fe0 static App.main() + 96 (App.swift:114)
32  MyApp                       0x0000000102c95a44 static MyAppApp.$main() + 28 (MyAppApp.swift:10)
33  MyApp                       0x0000000102c95a44 main + 40 (MyAppClass.swift:0)
34  dyld                            0x00000001a653ddf0 start + 2096 (dyldMain.cpp:1170)

从这个文档中,它说这是由于强制展开。然而,我使用武力包装非常少。我检查MyAppClass,里面没有强制upwrap,我检查了几个地方,我使用强制unwrap,也没有什么危险(我只把它用于局部变量,并且在做!之前总是检查!= nil)。

下面是自定义文本字段的样式:

struct CustomTextfieldStyle: TextFieldStyle {
private let font: Font
private let height: Double
init(font: Font, height: Double) {
self.font = font
self.height = height
}
func _body(configuration: TextField<Self._Label>) -> some View {
configuration
.font(font)
.foregroundColor(.white)
.padding(.horizontal, 10)
.frame(height: height)
.background(MyShape())
}
}

非正式地,当Appleclass,struct,func_开头时,标记为" private/undocumted"因此不可靠。

https://forums.swift.org/t/make-it-official-the-undocumented-private-api-signifier/47381

TextFieldStyle似乎没有提供任何bodypublic版本,并且此实现不遵循其他模式,如ButtonStyle,ToggleStyle,GaugeStyle等。

所有其他样式都使用func makeBody(configuration: Configuration)

我最初发表评论时并没有意识到这一点。

这是什么意思?,你不应该使用TextFieldStyle。相反,你应该创建一个包含所有样式的子视图,并使用该版本。

崩溃的第一行表明当获得CGRect时发生崩溃。如果你没有提供一个无效的高度,如0或-1故意或意外我的猜测是configuration提供了一个无效的CGRect

相关内容

  • 没有找到相关文章

最新更新