{"id":469210,"date":"2025-07-31T15:01:09","date_gmt":"2025-07-31T15:01:09","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=469210"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=469210","title":{"rendered":"<span>\u041f\u043e\u043a\u0430\u0436\u0443 \u0432\u0430\u043c \u0444\u043e\u043a\u0443\u0441: \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c property wrapper @FocusState \u2014 \u043a\u043e\u0440\u043e\u0442\u043a\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0414\u0435\u043c\u043c\u0438, \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f <a rel=\"noopener noreferrer nofollow\">AGIMA<\/a>. \u041c\u044b \u0447\u0430\u0441\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0431\u0430\u043d\u043a\u043e\u0432 \u0438\u043b\u0438 \u0435\u043a\u043e\u043c-\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u0418 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u044f: \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u043c\u044f, \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u044b, \u0430\u0434\u0440\u0435\u0441, \u043d\u043e\u043c\u0435\u0440\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0431\u0430\u043d\u043a\u043e\u0432\u0441\u043a\u0438\u0445 \u043a\u0430\u0440\u0442 \u0438\u043b\u0438 \u0440\u0435\u043a\u0432\u0438\u0437\u0438\u0442\u044b. \u0418\u043d\u043e\u0433\u0434\u0430 \u0442\u0430\u043a\u0438\u0445 \u0433\u0440\u0430\u0444 \u0431\u044b\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e, \u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438, \u0432 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f property wrapper @FocusState. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u0442\u0430\u043a\u0438\u043c, \u0442\u043e \u043d\u0438\u0436\u0435 \u0432\u0441\u0451 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/859\/727\/f3f\/859727f3fa3bfc7867fb8edf21ad1cc3.png\" width=\"1554\" height=\"806\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/859\/727\/f3f\/859727f3fa3bfc7867fb8edf21ad1cc3.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/859\/727\/f3f\/859727f3fa3bfc7867fb8edf21ad1cc3.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p>Property wrapper @FocusState \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 SwiftUI \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 iOS 15. \u041e\u043d \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u043e\u043a\u0443\u0441\u043e\u043c \u0434\u043b\u044f view \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u041d\u0438\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c UI-\u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f @FocusState \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 .toolbar \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0444\u043e\u043a\u0443\u0441\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430.\u00a0<\/p>\n<p>\u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0444\u043e\u0440\u043c, \u0430\u043d\u043a\u0435\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c view-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u0432\u0432\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f toolbar-\u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b.<\/p>\n<pre><code class=\"swift\">struct ContainerView&lt;Content: View&gt;: View {          @ViewBuilder let content: () -&gt; Content          var body: some View {         VStack {             content()         }         .toolbar {             ToolbarItem(placement: .keyboard) {                 toolbarItem             }         }     }          var toolbarItem: some View {         HStack {             Spacer()             Button(\"\u041d\u0430\u0437\u0430\u0434\") {                 moveToPreviousField()             }             Button(\"\u0414\u0430\u043b\u0435\u0435\") {                 moveToNextField()             }         }     }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c PreferenceKey \u0438 EnvironmentKey \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 view.<\/p>\n<pre><code class=\"swift\">struct FocusedFieldPreferences: PreferenceKey {          static var defaultValue: [UUID] = []          static func reduce(value: inout [UUID], nextValue: () -&gt; [UUID]) {         value.append(contentsOf: nextValue())     } } struct FocusFieldEnvironment: EnvironmentKey {     static let defaultValue: Binding&lt;UUID?&gt; = .constant(nil) } extension EnvironmentValues {     var focusField: Binding&lt;UUID?&gt; {         get { self[FocusFieldEnvironment.self] }         set { self[FocusFieldEnvironment.self] = newValue }     } }<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FocusedFieldPreferences \u0432 ContainerView \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 uuid \u0432\u0441\u0435\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 view, \u0430 \u0432 FocusFieldEnvironment \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c uuid \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e view, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0444\u043e\u043a\u0443\u0441\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 ContainerView:<\/p>\n<pre><code class=\"swift\">struct ContainerView&lt;Content: View&gt;: View {          @ViewBuilder let content: () -&gt; Content          @State var currentIndex: Int = 0          @State var childViewsIDs: [UUID?] = []     @State var focusedFieldID: UUID?          var body: some View {         VStack {             content()         }         .onPreferenceChange(FocusedFieldPreferences.self) { ids in             focusedFieldID = ids.first             childViewsIDs = ids         }         .environment(\\.focusField, $focusedFieldID)         .toolbar {             ToolbarItem(placement: .keyboard) {                 toolbarItem             }         }     }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043d\u043e\u043f\u043e\u043a \u0442\u0443\u043b\u0431\u0430\u0440\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"swift\">   private func moveToPreviousField() {         guard let currentID = focusedFieldID, let currentIndex = childViewsIDs.firstIndex(of: currentID), !childViewsIDs.isEmpty else { return }         let previousIndex = (currentIndex - 1 + childViewsIDs.count) % childViewsIDs.count         focusedFieldID = childViewsIDs[previousIndex]     }          private func moveToNextField() {         guard let currentID = focusedFieldID, let currentIndex = childViewsIDs.firstIndex(of: currentID), !childViewsIDs.isEmpty else { return }         let nextIndex = (currentIndex + 1) % childViewsIDs.count         focusedFieldID = childViewsIDs[nextIndex]     }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c ViewModifier \u0434\u043b\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 view, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u043a\u0443\u0441\u043e\u043c.<\/p>\n<pre><code class=\"swift\">struct FocusableModifier: ViewModifier {          @State private var id = UUID()          @FocusState private var isFocused: Bool          @Environment(\\.focusField) private var focusFromEnvironment          func body(content: Content) -&gt; some View {         content             .preference(key: FocusedFieldPreferences.self, value: [id])             .onChange(of: focusFromEnvironment.wrappedValue) { newValue in                 if newValue == id {                     isFocused = true                 }             }             .onChange(of: isFocused) { value in                 if value {                     focusFromEnvironment.wrappedValue = id                 }             }             .focused($isFocused)     } } extension View {       func focusable() -&gt; some View {         self.modifier(FocusableModifier())     }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0438\u0444\u0430\u0435\u0440 \u043a \u043d\u0443\u0436\u043d\u043e\u0439 view.<\/p>\n<pre><code class=\"swift\">struct CustomTextField: View {          var body: some View {                  TextField(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043a\u0441\u0442\", text: .constant(\"\"))             .focusable()     } }<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<figure class=\"\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/559\/e26\/eed\/559e26eed968479d870e7b1d772fe668.gif\" width=\"240\" height=\"472\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/559\/e26\/eed\/559e26eed968479d870e7b1d772fe668.gif 780w,&#10;       https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/559\/e26\/eed\/559e26eed968479d870e7b1d772fe668.gif 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><em>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c <\/em><a href=\"https:\/\/t.me\/WizAlx_will_tell\" rel=\"noopener noreferrer nofollow\"><em>\u043d\u0430 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b \u043c\u043e\u0435\u0433\u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0421\u0430\u0448\u0438 \u0412\u043e\u0440\u043e\u0436\u0438\u0449\u0435\u0432\u0430<\/em><\/a><em> \u2014 \u0442\u0430\u043c \u0432\u0441\u0451 \u043f\u0440\u043e \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443.\u00a0<\/em><\/p>\n<h2>\u0427\u0442\u043e \u0435\u0449\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/h2>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/821515\/\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u0434\u044b \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Swift<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/760698\/\" rel=\"noopener noreferrer nofollow\">PWA vs Native: \u0447\u0435\u043a-\u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/901736\/\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c PWA. \u041f\u043e\u043b\u043d\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Web App Manifest \u0438 Service Worker<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/932844\/\"> https:\/\/habr.com\/ru\/articles\/932844\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0412\u0441\u0435\u043c \u043f\u0440\u0438\u0432\u0435\u0442! \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0414\u043c\u0438\u0442\u0440\u0438\u0439 \u0414\u0435\u043c\u043c\u0438, \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f <a rel=\"noopener noreferrer nofollow\">AGIMA<\/a>. \u041c\u044b \u0447\u0430\u0441\u0442\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0434\u043b\u044f \u0431\u0430\u043d\u043a\u043e\u0432 \u0438\u043b\u0438 \u0435\u043a\u043e\u043c-\u043f\u0440\u043e\u0434\u0443\u043a\u0442\u043e\u0432. \u0418 \u0432 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u043f\u043e\u043b\u044f: \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0438\u043c\u044f, \u043a\u043e\u043d\u0442\u0430\u043a\u0442\u044b, \u0430\u0434\u0440\u0435\u0441, \u043d\u043e\u043c\u0435\u0440\u0430 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u0431\u0430\u043d\u043a\u043e\u0432\u0441\u043a\u0438\u0445 \u043a\u0430\u0440\u0442 \u0438\u043b\u0438 \u0440\u0435\u043a\u0432\u0438\u0437\u0438\u0442\u044b. \u0418\u043d\u043e\u0433\u0434\u0430 \u0442\u0430\u043a\u0438\u0445 \u0433\u0440\u0430\u0444 \u0431\u044b\u0432\u0430\u0435\u0442 \u043c\u043d\u043e\u0433\u043e, \u0438 \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0431\u044b\u043b\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0442\u044c\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u043d\u0438\u043c\u0438, \u0432 iOS-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f property wrapper @FocusState. \u0415\u0441\u043b\u0438 \u0432\u044b \u043f\u043e\u043a\u0430 \u043d\u0435 \u0441\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u043b\u0438\u0441\u044c \u0441 \u0442\u0430\u043a\u0438\u043c, \u0442\u043e \u043d\u0438\u0436\u0435 \u0432\u0441\u0451 \u043e\u0431\u044a\u044f\u0441\u043d\u044f\u044e \u0438 \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u044e.<\/p>\n<figure class=\"full-width\"><\/figure>\n<p>Property wrapper @FocusState \u043f\u043e\u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 SwiftUI \u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 iOS 15. \u041e\u043d \u0441\u0438\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u043b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0444\u043e\u043a\u0443\u0441\u043e\u043c \u0434\u043b\u044f view \u0438 \u0443\u043b\u0443\u0447\u0448\u0438\u043b \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u0441 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435\u043c. \u041d\u0438\u0436\u0435 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u0441\u043e\u0437\u0434\u0430\u0442\u044c UI-\u044d\u043b\u0435\u043c\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u0442 \u0432 \u0441\u0435\u0431\u044f @FocusState \u0438 \u043c\u043e\u0434\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 .toolbar \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0444\u043e\u043a\u0443\u0441\u0430 \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u043b\u044f\u043c\u0438 \u0432\u0432\u043e\u0434\u0430.\u00a0<\/p>\n<p>\u0415\u0433\u043e \u043c\u043e\u0436\u043d\u043e \u043f\u0435\u0440\u0435\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0432 \u0440\u0430\u0437\u043d\u044b\u0445 \u0447\u0430\u0441\u0442\u044f\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f. \u042d\u0442\u043e \u0441\u043d\u0438\u0436\u0430\u0435\u0442 \u0434\u0443\u0431\u043b\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u043e\u0434\u0430, \u0447\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0432\u0430\u0436\u043d\u043e \u043d\u0430 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u0445 \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e\u043c \u0444\u043e\u0440\u043c, \u0430\u043d\u043a\u0435\u0442 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u0439, \u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0448\u0435.<\/p>\n<p>\u041f\u0435\u0440\u0432\u044b\u043c \u0434\u0435\u043b\u043e\u043c \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c view-\u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043f\u043e\u043b\u0435\u0439 \u0432\u0432\u043e\u0434\u0430, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u043c \u043a\u043d\u043e\u043f\u043a\u0438 \u0434\u043b\u044f toolbar-\u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b.<\/p>\n<pre><code class=\"swift\">struct ContainerView&lt;Content: View&gt;: View {          @ViewBuilder let content: () -&gt; Content          var body: some View {         VStack {             content()         }         .toolbar {             ToolbarItem(placement: .keyboard) {                 toolbarItem             }         }     }          var toolbarItem: some View {         HStack {             Spacer()             Button(\"\u041d\u0430\u0437\u0430\u0434\") {                 moveToPreviousField()             }             Button(\"\u0414\u0430\u043b\u0435\u0435\") {                 moveToNextField()             }         }     }<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c PreferenceKey \u0438 EnvironmentKey \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u0440\u043e\u0434\u0438\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0438 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 view.<\/p>\n<pre><code class=\"swift\">struct FocusedFieldPreferences: PreferenceKey {          static var defaultValue: [UUID] = []          static func reduce(value: inout [UUID], nextValue: () -&gt; [UUID]) {         value.append(contentsOf: nextValue())     } } struct FocusFieldEnvironment: EnvironmentKey {     static let defaultValue: Binding&lt;UUID?&gt; = .constant(nil) } extension EnvironmentValues {     var focusField: Binding&lt;UUID?&gt; {         get { self[FocusFieldEnvironment.self] }         set { self[FocusFieldEnvironment.self] = newValue }     } }<\/code><\/pre>\n<p>\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e FocusedFieldPreferences \u0432 ContainerView \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 uuid \u0432\u0441\u0435\u0445 \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 view, \u0430 \u0432 FocusFieldEnvironment \u0431\u0443\u0434\u0435\u043c \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c uuid \u0442\u043e\u043b\u044c\u043a\u043e \u0442\u043e\u0433\u043e \u0434\u043e\u0447\u0435\u0440\u043d\u0435\u0433\u043e view, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0434\u043e\u043b\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0432 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0438 \u0444\u043e\u043a\u0443\u0441\u0430.<\/p>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u043d\u0430\u0448 ContainerView:<\/p>\n<pre><code class=\"swift\">struct ContainerView&lt;Content: View&gt;: View {          @ViewBuilder let content: () -&gt; Content          @State var currentIndex: Int = 0          @State var childViewsIDs: [UUID?] = []     @State var focusedFieldID: UUID?          var body: some View {         VStack {             content()         }         .onPreferenceChange(FocusedFieldPreferences.self) { ids in             focusedFieldID = ids.first             childViewsIDs = ids         }         .environment(\\.focusField, $focusedFieldID)         .toolbar {             ToolbarItem(placement: .keyboard) {                 toolbarItem             }         }     }<\/code><\/pre>\n<p>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0434\u043b\u044f \u043a\u043d\u043e\u043f\u043e\u043a \u0442\u0443\u043b\u0431\u0430\u0440\u0430 \u043a\u043b\u0430\u0432\u0438\u0430\u0442\u0443\u0440\u044b:<\/p>\n<pre><code class=\"swift\">   private func moveToPreviousField() {         guard let currentID = focusedFieldID, let currentIndex = childViewsIDs.firstIndex(of: currentID), !childViewsIDs.isEmpty else { return }         let previousIndex = (currentIndex - 1 + childViewsIDs.count) % childViewsIDs.count         focusedFieldID = childViewsIDs[previousIndex]     }          private func moveToNextField() {         guard let currentID = focusedFieldID, let currentIndex = childViewsIDs.firstIndex(of: currentID), !childViewsIDs.isEmpty else { return }         let nextIndex = (currentIndex + 1) % childViewsIDs.count         focusedFieldID = childViewsIDs[nextIndex]     }<\/code><\/pre>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u043c \u0448\u0430\u0433\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c ViewModifier \u0434\u043b\u044f \u0434\u043e\u0447\u0435\u0440\u043d\u0438\u0445 view, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043c\u044b \u0445\u043e\u0442\u0438\u043c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u043e\u043a\u0443\u0441\u043e\u043c.<\/p>\n<pre><code class=\"swift\">struct FocusableModifier: ViewModifier {          @State private var id = UUID()          @FocusState private var isFocused: Bool          @Environment(\\.focusField) private var focusFromEnvironment          func body(content: Content) -&gt; some View {         content             .preference(key: FocusedFieldPreferences.self, value: [id])             .onChange(of: focusFromEnvironment.wrappedValue) { newValue in                 if newValue == id {                     isFocused = true                 }             }             .onChange(of: isFocused) { value in                 if value {                     focusFromEnvironment.wrappedValue = id                 }             }             .focused($isFocused)     } } extension View {       func focusable() -&gt; some View {         self.modifier(FocusableModifier())     }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u043c\u043e\u0434\u0438\u0444\u0430\u0435\u0440 \u043a \u043d\u0443\u0436\u043d\u043e\u0439 view.<\/p>\n<pre><code class=\"swift\">struct CustomTextField: View {          var body: some View {                  TextField(\"\u0412\u0432\u0435\u0434\u0438\u0442\u0435 \u0442\u0435\u043a\u0441\u0442\", text: .constant(\"\"))             .focusable()     } }<\/code><\/pre>\n<p>\u0412 \u0438\u0442\u043e\u0433\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0447\u0442\u043e-\u0442\u043e \u0432\u0440\u043e\u0434\u0435 \u044d\u0442\u043e\u0433\u043e:<\/p>\n<figure class=\"\"><\/figure>\n<p><em>\u0415\u0441\u043b\u0438 \u0443 \u0432\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0438\u0441\u044c \u0432\u043e\u043f\u0440\u043e\u0441\u044b, \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043e\u0442\u0432\u0435\u0442\u0438\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u0438\u0442\u0435\u0441\u044c \u043e\u043f\u044b\u0442\u043e\u043c \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445 \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0439\u0442\u0435\u0441\u044c <\/em><a href=\"https:\/\/t.me\/WizAlx_will_tell\" rel=\"noopener noreferrer nofollow\"><em>\u043d\u0430 \u0442\u0435\u043b\u0435\u0433\u0440\u0430\u043c-\u043a\u0430\u043d\u0430\u043b \u043c\u043e\u0435\u0433\u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0421\u0430\u0448\u0438 \u0412\u043e\u0440\u043e\u0436\u0438\u0449\u0435\u0432\u0430<\/em><\/a><em> \u2014 \u0442\u0430\u043c \u0432\u0441\u0451 \u043f\u0440\u043e \u043c\u043e\u0431\u0438\u043b\u044c\u043d\u0443\u044e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0443.\u00a0<\/em><\/p>\n<h2>\u0427\u0442\u043e \u0435\u0449\u0435 \u043f\u043e\u0447\u0438\u0442\u0430\u0442\u044c<\/h2>\n<ul>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/821515\/\" rel=\"noopener noreferrer nofollow\">\u0412\u0438\u0434\u044b \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0432 Swift<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/760698\/\" rel=\"noopener noreferrer nofollow\">PWA vs Native: \u0447\u0435\u043a-\u043b\u0438\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0431\u0440\u0430\u0442\u044c<\/a><\/p>\n<\/li>\n<li>\n<p><a href=\"https:\/\/habr.com\/ru\/companies\/agima\/articles\/901736\/\" rel=\"noopener noreferrer nofollow\">\u0420\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c PWA. \u041f\u043e\u043b\u043d\u0430\u044f \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f \u043f\u043e \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 Web App Manifest \u0438 Service Worker<\/a><\/p>\n<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/932844\/\"> https:\/\/habr.com\/ru\/articles\/932844\/<\/a><br \/><\/br><\/br><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-469210","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469210","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=469210"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/469210\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=469210"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=469210"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=469210"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}