RenameButton

A button that triggers a standard rename action.

ComponentiOS 16.0+macOS 13.0+tvOS 16.0+watchOS 9.0+RenameButton in SwiftUI

Declaration

React
import { RenameButton } from 'swiftui-react-native';
Swift
nonisolated struct RenameButton<Label> where Label : View

Initializers

One SwiftUI initializer backs <RenameButton>.

React
<RenameButton />
Swift
nonisolated init() where Label == Label<Text, Image>

Takes no props.

Also takes the common view props: modifiers, style and testID.

Overview

A rename button receives its action from the environment. Use the View.renameAction(_:) modifier to set the action. The system disables the button if you don't define an action.

struct RowView: View {
    @State private var text = ""
    @FocusState private var isFocused: Bool

    var body: some View {
        TextField(text: $text) {
            Text("Prompt")
        }
        .focused($isFocused)
        .contextMenu {
            RenameButton()
            // ... your own custom actions
        }
        .renameAction { isFocused = true }
    }
}

When someone taps the rename button in the context menu, the rename action focuses the text field by setting the isFocused property to true.

You can use this button inside of a navigation title menu and the navigation title modifier automatically configures the environment with the appropriate rename action.

ContentView()
    .navigationTitle($contentTitle)
    .toolbarTitleMenu {
        // ... your own custom actions
        RenameButton()
    }

From Apple’s SwiftUI documentation. Code samples there are Swift.

Relationships

Conforms to

  • View

See also

More in Views.