Skip to content

Commit 00524eb

Browse files
committed
fix: allow to manually move dev menu to avoid conflicts
1 parent fa26a3b commit 00524eb

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

packages/react-native/Libraries/SwiftExtensions/RCTMainWindow.swift

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public struct RCTMainWindow: Scene {
2222
var moduleName: String
2323
var initialProps: RCTRootViewRepresentable.InitialPropsType
2424
var onOpenURLCallback: ((URL) -> ())?
25-
var devMenuPlacement: ToolbarPlacement = .bottomOrnament
25+
var devMenuPlacement: OrnamentAttachmentAnchor? = .scene(.bottom)
2626
var contentView: AnyView?
2727

2828
var rootView: RCTRootViewRepresentable {
@@ -38,7 +38,7 @@ public struct RCTMainWindow: Scene {
3838
public init(
3939
moduleName: String,
4040
initialProps: RCTRootViewRepresentable.InitialPropsType = nil,
41-
devMenuPlacement: ToolbarPlacement = .bottomOrnament
41+
devMenuPlacement: OrnamentAttachmentAnchor? = .scene(.bottom)
4242
) {
4343
self.moduleName = moduleName
4444
self.initialProps = initialProps
@@ -56,7 +56,7 @@ public struct RCTMainWindow: Scene {
5656
public init<Content: View>(
5757
moduleName: String,
5858
initialProps: RCTRootViewRepresentable.InitialPropsType = nil,
59-
devMenuPlacement: ToolbarPlacement = .bottomOrnament,
59+
devMenuPlacement: OrnamentAttachmentAnchor? = .scene(.bottom),
6060
@ViewBuilder contentView: @escaping (_ view: RCTRootViewRepresentable) -> Content
6161
) {
6262
self.moduleName = moduleName
@@ -73,8 +73,10 @@ public struct RCTMainWindow: Scene {
7373
onOpenURLCallback?(url)
7474
})
7575
#if DEBUG
76-
.toolbar {
77-
DevMenuView(placement: .bottomOrnament)
76+
.if(devMenuPlacement != nil) { content in
77+
content.ornament(attachmentAnchor: devMenuPlacement!) {
78+
DevMenuView()
79+
}
7880
}
7981
#endif
8082
}
@@ -142,18 +144,14 @@ public struct WindowHandlingModifier: ViewModifier {
142144
/**
143145
Toolbar which displays additional controls to easily open dev menu and trigger reload command.
144146
*/
145-
struct DevMenuView: ToolbarContent {
146-
let placement: ToolbarItemPlacement
147-
148-
var body: some ToolbarContent {
149-
ToolbarItem(placement: placement) {
147+
struct DevMenuView: View {
148+
var body: some View {
149+
VStack {
150150
Button(action: {
151151
RCTTriggerReloadCommandListeners("User Reload")
152152
}, label: {
153153
Image(systemName: "arrow.clockwise")
154154
})
155-
}
156-
ToolbarItem(placement: placement) {
157155
Button(action: {
158156
NotificationCenter.default.post(
159157
Notification(name: Notification.Name("RCTShowDevMenuNotification"), object: nil)
@@ -162,6 +160,21 @@ struct DevMenuView: ToolbarContent {
162160
label: {
163161
Image(systemName: "filemenu.and.selection")
164162
})
165-
}
163+
}.glassBackgroundEffect()
166164
}
167165
}
166+
167+
extension View {
168+
/// Applies the given transform if the given condition evaluates to `true`.
169+
/// - Parameters:
170+
/// - condition: The condition to evaluate.
171+
/// - transform: The transform to apply to the source `View`.
172+
/// - Returns: Either the original `View` or the modified `View` if the condition is `true`.
173+
@ViewBuilder func `if`<Content: View>(_ condition: @autoclosure () -> Bool, transform: (Self) -> Content) -> some View {
174+
if condition() {
175+
transform(self)
176+
} else {
177+
self
178+
}
179+
}
180+
}

0 commit comments

Comments
 (0)