EditMode
A mode that indicates whether the user can edit a view's content.
Declaration
type EditMode = 'active' | 'inactive' | 'transient';enum EditModePass a literal, or build one with SwiftUI.EditMode from import { SwiftUI } from 'swiftui-react-native'.
Type properties
'active'SwiftUI.EditMode.active'inactive'SwiftUI.EditMode.inactive'transient'SwiftUI.EditMode.transient
Overview
You receive an optional binding to the edit mode state when you
read the EnvironmentValues.editMode environment value. The binding
contains an EditMode value that indicates whether edit mode is active,
and that you can use to change the mode. To learn how to read an environment
value, see EnvironmentValues.
Certain built-in views automatically alter their appearance and behavior
in edit mode. For example, a List with a ForEach that's
configured with the DynamicViewContent.onDelete(perform:) or
DynamicViewContent.onMove(perform:) modifier provides controls to
delete or move list items while in edit mode. On devices without an attached
keyboard and mouse or trackpad, people can make multiple selections in lists
only when edit mode is active.
You can also customize your own views to react to edit mode.
The following example replaces a read-only Text view with
an editable TextField, checking for edit mode by
testing the wrapped value's EditMode.isEditing property:
@Environment(\.editMode) private var editMode
@State private var name = "Maria Ruiz"
var body: some View {
Form {
if editMode?.wrappedValue.isEditing == true {
TextField("Name", text: $name)
} else {
Text(name)
}
}
.animation(nil, value: editMode?.wrappedValue)
.toolbar { // Assumes embedding this view in a NavigationView.
EditButton()
}
}You can set the edit mode through the binding, or you can
rely on an EditButton to do that for you, as the example above
demonstrates. The button activates edit mode when the user
taps it, and disables the mode when the user taps again.
From Apple’s SwiftUI documentation. Code samples there are Swift.
See also
More in Other values.
- AxisThe horizontal or vertical dimension in a 2D coordinate system.
- AxisSetAn efficient set of axes.
- ButtonRoleA value that describes the purpose of a button.
- CapsuleA capsule shape aligned inside the frame of the view containing it.
- CircleA circle centered on the frame of the view containing it.
- ConcentricRectangleA shape whose corners you configure, individually or uniformly, to be squared, rounded, or concentric relative to a container shape's corners.
- ContentMarginGuideA guide for resolving the content margins for a view.
- ContentMarginPlacementThe placement of margins.
- ContentModeConstants that define how a view's content fills the available space.
- DatePickerComponents
- DatePickerComponents2The date and time components that a date picker shows.
- DeviceHingeA type encapsulating the state of a single hinge.