<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ShoheOhtani</title>
    <description>The latest articles on DEV Community by ShoheOhtani (@shohe).</description>
    <link>https://dev.to/shohe</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F882816%2F8b396c0a-9a0d-4332-9514-ba8fe3c86ccc.jpeg</url>
      <title>DEV Community: ShoheOhtani</title>
      <link>https://dev.to/shohe</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shohe"/>
    <language>en</language>
    <item>
      <title>[SwiftUI] Animate placeholder modifier for View</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Sat, 22 Oct 2022 01:41:28 +0000</pubDate>
      <link>https://dev.to/shohe/swiftui-animate-placeholder-modifier-for-view-5d06</link>
      <guid>https://dev.to/shohe/swiftui-animate-placeholder-modifier-for-view-5d06</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0km0a51cizeqesik1gus.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0km0a51cizeqesik1gus.gif" alt="Image description" width="800" height="457"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// prepare `isLoading: Bool` variable.
VStack { ... }
    .redacted(reason: viewModel.isLoading ? .placeholder : [])
    .animatePlaceholder(isLoading: $isLoading)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  2 Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create AnimatePlaceholderModifier&lt;/li&gt;
&lt;li&gt;Add extension method to View&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step1: Create AnimatePlaceholderModifier&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct AnimatePlaceholderModifier: AnimatableModifier {
    @Binding var isLoading: Bool

    @State private var isAnim: Bool = false
    private var center = (UIScreen.main.bounds.width / 2) + 110
    private let animation: Animation = .linear(duration: 1.5)

    init(isLoading: Binding&amp;lt;Bool&amp;gt;) {
        self._isLoading = isLoading
    }

    func body(content: Content) -&amp;gt; some View {
        content.overlay(animView.mask(content))
    }

    var animView: some View {
        ZStack {
            Color.black.opacity(isLoading ? 0.09 : 0.0)
            Color.white.mask(
                Rectangle()
                    .fill(
                        LinearGradient(gradient: .init(colors: [.clear, .white.opacity(0.48), .clear]), startPoint: .top , endPoint: .bottom)
                    )
                    .scaleEffect(1.5)
                    .rotationEffect(.init(degrees: 70.0))
                    .offset(x: isAnim ? center : -center)
            )
        }
        .animation(isLoading ? animation.repeatForever(autoreverses: false) : nil, value: isAnim)
        .onAppear {
            guard isLoading else { return }
            isAnim.toggle()
        }
        .onChange(of: isLoading) { _ in
            isAnim.toggle()
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step2: Add extension method to View&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extension View {
    func animatePlaceholder(isLoading: Binding&amp;lt;Bool&amp;gt;) -&amp;gt; some View {
        self.modifier(AnimatePlaceholderModifier(isLoading: isLoading))
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>swiftui</category>
      <category>swift</category>
      <category>ios</category>
      <category>uiux</category>
    </item>
    <item>
      <title>[ReactNative] How to control view orientation for Native Module</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Wed, 21 Sep 2022 10:46:08 +0000</pubDate>
      <link>https://dev.to/shohe/reactnative-how-to-control-view-orientation-for-native-module-3f8n</link>
      <guid>https://dev.to/shohe/reactnative-how-to-control-view-orientation-for-native-module-3f8n</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xHD9BqtW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdn8so2cp7gielkof0vo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xHD9BqtW--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xdn8so2cp7gielkof0vo.png" alt="Image description" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  3 Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Modify &lt;code&gt;AppDelegate.h&lt;/code&gt; / &lt;code&gt;AppDelegate.m&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Create &lt;code&gt;AppUtility.swift&lt;/code&gt; for update orientation easily&lt;/li&gt;
&lt;li&gt;Fix view's position for ReactNative&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step1: Modify AppDelegate&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;AppDelegate.h&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// add property
@property (nonatomic, assign) UIInterfaceOrientationMask orientationLock;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;AppDelegate.m&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
  return _orientationLock;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{ ...
// default value
_orientationLock = UIInterfaceOrientationMaskPortrait; 
...
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step2: Create AppUtility.swift&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct AppUtility {
  static func lockOrientation(_ orientation: UIInterfaceOrientationMask) {
    if let delegate = UIApplication.shared.delegate as? AppDelegate {
      delegate.orientationLock = orientation
    }
  }

  /// OPTIONAL Added method to adjust lock and rotate to the desired orientation
  static func lockOrientation(_ orientation: UIInterfaceOrientationMask, andRotateTo rotateOrientation:UIInterfaceOrientation) {
    self.lockOrientation(orientation)

    UIDevice.current.setValue(rotateOrientation.rawValue, forKey: "orientation")
    UINavigationController.attemptRotationToDeviceOrientation()
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step3: Fix view's position for ReactNative&lt;/strong&gt;&lt;br&gt;
When you update orientation, view's position will move wrong position. So, when it's happened call this function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private func fixViewPosition() {
    // Wait 0.1 sec and fix position.
    // It wont be fixed position in some case, so fix twice with 0.1 sec delay for that wired bug.
    DispatchQueue.main.asyncAfter(deadline: .now()+0.1) { [self] in
      let fixedPosition = CGPoint(x: -UIScreen.main.bounds.midX + targetView.bounds.midX, y: -UIScreen.main.bounds.midY + targetView.bounds.midY)
      view.bounds.origin = fixedPosition
      DispatchQueue.main.asyncAfter(deadline: .now()+0.1) { [self] in view.bounds.origin = fixedPosition }
    }
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>[SwiftUI] How to set custom font to NavigationBarTitle</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Sun, 04 Sep 2022 04:36:05 +0000</pubDate>
      <link>https://dev.to/shohe/swiftui-how-to-set-custom-font-to-navigationbartitle-2n2e</link>
      <guid>https://dev.to/shohe/swiftui-how-to-set-custom-font-to-navigationbartitle-2n2e</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwlheeo8kniea2b5ekgix.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fwlheeo8kniea2b5ekgix.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You need to install &lt;code&gt;Introspect&lt;/code&gt; &lt;a href="https://github.com/siteline/SwiftUI-Introspect" rel="noopener noreferrer"&gt;library&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;

&lt;p&gt;It should be used on root of navigationView. If you use&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

NavigationView {
    VStack { ... }
        // ↓ set custom font
        .navigationTitleFont(font: UIFont.custom.extraBold(ofSize: 20))
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;h2&gt;
  
  
  3 Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create ViewModifier&lt;/li&gt;
&lt;li&gt;Add extension method to UIFont&lt;/li&gt;
&lt;li&gt;Add extension method to View&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step1: Create ViewModifier&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

import SwiftUI
import Introspect

public struct NavigationTitleFontModifier: ViewModifier {
    public var font: UIFont

    public func body(content: Content) -&amp;gt; some View {
        content
            .introspectNavigationController {
                $0.navigationBar.titleTextAttributes = [.font:font]
            }
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step2: Add extension method to UIFont&lt;/strong&gt;&lt;br&gt;
This is unnecessary. It just for make call custom font easily.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

extension UIFont {
    public struct custom {
        static func extraBold(ofSize size: CGFloat) -&amp;gt; UIFont {
            return UIFont(name: "BoldCustomFontName", size: size) ?? UIFont.systemFont(ofSize: size, weight: .bold)
        }
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;Step3: Add extension method to View&lt;/strong&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

public extension View {
    func navigationTitleFont(font: UIFont) -&amp;gt; some View {
        self.modifier(NavigationTitleFontModifier(font: font))
    }
}


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
    </item>
    <item>
      <title>[Swift/SwiftUI] How to fix "Attempt to present which is already presenting"</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Fri, 12 Aug 2022 15:59:57 +0000</pubDate>
      <link>https://dev.to/shohe/swiftswiftui-how-to-fix-attempt-to-present-which-is-already-presenting-6ja</link>
      <guid>https://dev.to/shohe/swiftswiftui-how-to-fix-attempt-to-present-which-is-already-presenting-6ja</guid>
      <description>&lt;p&gt;When you implement present ViewController like Modal, some of case you'd see "Attempt to present which is already presenting".&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Before code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;uiView.window?.rootViewController?.present(viewController, animated: true)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Error log&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Presentation] Attempt to present &amp;lt;UIViewController: 0x10c72d050&amp;gt; on &amp;lt;_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x10c60ab30&amp;gt; (from &amp;lt;_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x10c60ab30&amp;gt;) which is already presenting &amp;lt;UIViewController: 0x1201f72b0&amp;gt;.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;After code&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;guard let rootViewController = 
uiView.window?.rootViewController else { return }
if rootViewController.presentedViewController == nil {
    rootViewController.present(viewController, animated: true)
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>[SwiftUI] How to create Toast View</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Sat, 16 Jul 2022 03:23:25 +0000</pubDate>
      <link>https://dev.to/shohe/swiftui-toast-view-27cd</link>
      <guid>https://dev.to/shohe/swiftui-toast-view-27cd</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6hPQjRAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2v7ku2m11dzijmtpb1y.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6hPQjRAO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c2v7ku2m11dzijmtpb1y.jpg" alt="Image description" width="880" height="660"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to use
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct ContentView: View {
    @State var presentTop: Bool = false

    var body: some View {
        VStack {
            TPButton(title: "☝️", action: {
                presentTop = true
            })
        }
        .navigationBarTitleDisplayMode(.inline) // if it's needed
        .toast(isPresented: $presentTop, edge: .top) { toastContent }
    }

    var toastContent: some View {
        HStack {
            Image(systemName: "checkmark.circle").font(.headline)
            Text("Toast!").font(.headline)
        }
        .frame(maxHeight: .infinity)
        .padding()
        .background(RoundedRectangle(cornerRadius: 8.0).foregroundColor(.random)) // set color whatever you want
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3 Steps
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create ToastView&lt;/li&gt;
&lt;li&gt;Create ViewModifier&lt;/li&gt;
&lt;li&gt;Create ViewModifier&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Step1: Create ToastView&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct Toast&amp;lt;Content:View&amp;gt;: View {
    @Binding var isPresented: Bool
    @State var edge: Edge
    var content: Content
    let action: (() -&amp;gt; Void)?

    private var alignment: Alignment {
        switch edge {
        case .top: return .top
        case .leading: return .leading
        case .bottom: return .bottom
        case .trailing: return .trailing
        }
    }

    init(isPresented: Binding&amp;lt;Bool&amp;gt;, edge: Edge, action: (() -&amp;gt; Void)? = nil, @ViewBuilder content: () -&amp;gt; Content) {
        _isPresented = isPresented
        _edge = State(wrappedValue: edge)
        self.action = action
        self.content = content()
    }

    var body: some View {
        ZStack(alignment: alignment) {
            Spacer().frame(maxWidth: .infinity, maxHeight: .infinity)
            content
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .padding()
        .animation(.spring(), value: isPresented)
        .transition(.move(edge: edge).combined(with: .opacity))
        .onTapGesture {
            withAnimation {
                isPresented = false
                action?()
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step2: Create ViewModifier&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct ToastModifier&amp;lt;ToastContent: View&amp;gt;: ViewModifier {

    @Binding var isPresented: Bool
    var toast: Toast&amp;lt;ToastContent&amp;gt;

    init(isPresented: Binding&amp;lt;Bool&amp;gt;, edge: Edge, action: (() -&amp;gt; Void)? = nil, @ViewBuilder toastContent: () -&amp;gt; ToastContent) {
        _isPresented = isPresented
        toast = Toast(isPresented: isPresented, edge: edge, action: action, content: toastContent)
    }

    public func body(content: Content) -&amp;gt; some View {
        ZStack {
            content
            if isPresented { toast }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .background(Color.clear.ignoresSafeArea(.all, edges: .all))
        .animation(.spring(), value: isPresented)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Step3: View Extension&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public extension View {
    func toast&amp;lt;Content:View&amp;gt;(isPresented: Binding&amp;lt;Bool&amp;gt;, edge: Edge, action: (() -&amp;gt; Void)? = nil, @ViewBuilder content: () -&amp;gt; Content) -&amp;gt; some View {
        self.modifier(ToastModifier(isPresented: isPresented, edge: edge, action: action, toastContent: content))
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>[ReactNative] How to solve "Unable to resolve module xxx"</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Wed, 13 Jul 2022 05:23:02 +0000</pubDate>
      <link>https://dev.to/shohe/reactnative-how-to-solve-unable-to-resolve-module-xxx-4fe5</link>
      <guid>https://dev.to/shohe/reactnative-how-to-solve-unable-to-resolve-module-xxx-4fe5</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3henAzA5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ws6phg86xpembfvhrs4a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3henAzA5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ws6phg86xpembfvhrs4a.png" alt="Image description" width="880" height="465"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;1: rm -rf ios/build&lt;br&gt;
2: rm -rf node_modules&lt;br&gt;
3: npm cache clean --force&lt;br&gt;
4: npm install&lt;br&gt;
5: npm start -- --reset-cache&lt;br&gt;
6: npx react-native run-ios&lt;/p&gt;

</description>
    </item>
    <item>
      <title>[SwiftUI] Change background color of NavigationView &amp; Form</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Mon, 04 Jul 2022 00:19:31 +0000</pubDate>
      <link>https://dev.to/shohe/swiftui-change-background-color-of-navigationview-form-3lpf</link>
      <guid>https://dev.to/shohe/swiftui-change-background-color-of-navigationview-form-3lpf</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F958m892uz21f2wd87oi2.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F958m892uz21f2wd87oi2.JPG" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We need to modify &lt;code&gt;NavigationView&lt;/code&gt; &amp;amp; &lt;code&gt;Form&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NavigationView {
    VStack(alignment: .leading, spacing: 0.0) {
        Form {
            Section {
                NavigationLink(destination: EmptyView()) {
                    Text("-")
                }
                ...
            }
        }.backgroundColor(.black) 👈
    }
    .navigationBarTitle("Settings", displayMode: .inline)
    .navigationBarColor(.black, tintColor: .white) 👈
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Modify NavigationView&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct NavigationBarModifier: ViewModifier {
    var backgroundColor: UIColor?

    init(backgroundColor: UIColor?, tintColor: UIColor?) {
        self.backgroundColor = backgroundColor

        let coloredAppearance = UINavigationBarAppearance()
        coloredAppearance.configureWithTransparentBackground()
        coloredAppearance.backgroundColor = .clear
        coloredAppearance.titleTextAttributes = [.foregroundColor: tintColor as Any]
        coloredAppearance.largeTitleTextAttributes = [.foregroundColor: tintColor as Any]

        UINavigationBar.appearance().standardAppearance = coloredAppearance
        UINavigationBar.appearance().compactAppearance = coloredAppearance
        UINavigationBar.appearance().scrollEdgeAppearance = coloredAppearance
        UINavigationBar.appearance().tintColor = tintColor

    }

    func body(content: Content) -&amp;gt; some View {
        ZStack{
            content
            VStack {
                GeometryReader { geometry in
                    Color(self.backgroundColor ?? .clear)
                        .frame(height: geometry.safeAreaInsets.top)
                        .edgesIgnoringSafeArea(.top)
                    Spacer()
                }
            }
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extension View {

    func navigationBarColor(_ backgroundColor: Color?, tintColor: Color?) -&amp;gt; some View {
        self.modifier(NavigationBarModifier(backgroundColor: UIColor(backgroundColor ?? .white), tintColor: UIColor(tintColor ?? .black)))
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Modify Form&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;struct FormModifier: ViewModifier {

    init(backgroundColor: UIColor?) {
        UITableView.appearance().backgroundColor = backgroundColor
    }

    func body(content: Content) -&amp;gt; some View {
        content
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;extension Form {

    func backgroundColor(_ backgroundColor: Color?) -&amp;gt; some View {
        self.modifier(FormModifier(backgroundColor: UIColor(backgroundColor ?? .white)))
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>swift</category>
      <category>design</category>
      <category>ios</category>
    </item>
    <item>
      <title>[Swift] How to fetch only screenShot &amp; screenRecording from photo library</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Wed, 29 Jun 2022 06:46:05 +0000</pubDate>
      <link>https://dev.to/shohe/swift-how-to-fetch-only-screenshot-screenrecording-from-photo-library-54od</link>
      <guid>https://dev.to/shohe/swift-how-to-fetch-only-screenshot-screenrecording-from-photo-library-54od</guid>
      <description>&lt;p&gt;Apple doesn't prepare enum for screenRecording like &lt;code&gt;.photoScreenshot&lt;/code&gt; in &lt;code&gt;PHAssetMediaSubtype&lt;/code&gt;. However screenRecording asset has mediaSubtype which is &lt;code&gt;524288&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import SwiftUI
import Photos

...
var photos: [Asset] = []

func fetchPhotos() {
    let options = PHFetchOptions()
    options.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
    options.predicate = NSPredicate(format: "((mediaSubtype &amp;amp; %d) != 0 || (mediaSubtype &amp;amp; %d) != 0)", PHAssetMediaSubtype.photoScreenshot.rawValue, 524288)
    options.includeHiddenAssets = false

    let result = PHAsset.fetchAssets(with: options)
    result.enumerateObjects { asset, index, _ in
        Task {
            guard let image: UIImage = await self.getImageFromAsset(asset: asset, size: CGSize(width: self.assetSize, height: self.assetSize)) else { return }
            DispatchQueue.main.async { [weak self] in
                self?.photos.append(Asset(asset: asset, image: image))
            }
        }
    }
}

private func getImageFromAsset(asset: PHAsset, size: CGSize) async -&amp;gt; UIImage? {
    return await withCheckedContinuation { continuation in
        let manager = PHCachingImageManager()
        manager.allowsCachingHighQualityImages = true

        let options = PHImageRequestOptions()
        options.deliveryMode = .highQualityFormat
        options.isSynchronous = false
        manager.requestImage(for: asset, targetSize: size, contentMode: .aspectFill, options: options) { image, _ in
            continuation.resume(returning: image)
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>[Kotlin] How to create CustomView reusable</title>
      <dc:creator>ShoheOhtani</dc:creator>
      <pubDate>Tue, 28 Jun 2022 10:13:31 +0000</pubDate>
      <link>https://dev.to/shohe/kotlin-how-to-create-customview-reusable-3eih</link>
      <guid>https://dev.to/shohe/kotlin-how-to-create-customview-reusable-3eih</guid>
      <description>&lt;p&gt;&lt;strong&gt;1. RightClick &amp;gt; UiComponent &amp;gt; Custom View&lt;/strong&gt;&lt;br&gt;
There will be 3 new files created &lt;code&gt;CustomView.kt&lt;/code&gt;, &lt;code&gt;view_custom.xml&lt;/code&gt;, &lt;code&gt;attrs_custom_view.xml&lt;/code&gt;(You can delete if you want).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Edit view_custom.xml&lt;/strong&gt;&lt;br&gt;
Delete views no need and convert Layout to LinearLayout (vertical or horizontal)&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HdAHnjFH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9mhnyilmm0b8u4rq0lx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HdAHnjFH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n9mhnyilmm0b8u4rq0lx.png" alt="Image description" width="880" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Edit CustomView.kt&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class CustomView: LinearLayout {
    constructor(context: Context?) : super(context)
    constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
    constructor(context: Context?, attrs: AttributeSet?, defStyle: Int) : super(context, attrs, defStyle)

    init {
        LayoutInflater.from(context).inflate(R.layout.view_custom, this)
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to get object on layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;private val someTextView: TextView by lazy { findViewById(R.id.some_text_view) }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
