Sha256: facb7431d0297dfdc0cd50176554d1104f463eb17c33eb48ef8c7624317f6091

Contents?: true

Size: 1.46 KB

Versions: 18

Compression:

Stored size: 1.46 KB

Contents

import Foundation
import Strada
import UIKit

final class NavButtonComponent: BridgeComponent {
    override class var name: String { "nav-button" }

    override func onReceive(message: Message) {
        guard let event = Event(rawValue: message.event) else {
            return
        }

        if event == .connect {
            handleConnectEvent(message: message)
        }
    }

    @objc func performAction() {
        reply(to: Event.connect.rawValue)
    }

    // MARK: Private

    private weak var navBarButtonItem: UIBarButtonItem?

    private var viewController: UIViewController? {
        delegate.destination as? UIViewController
    }

    private func handleConnectEvent(message: Message) {
        guard let data: MessageData = message.data() else { return }
        configureBarButton(with: data.title)
    }

    private func configureBarButton(with title: String) {
        guard let viewController else { return }

        let item = UIBarButtonItem(title: title,
                                   style: .plain,
                                   target: self,
                                   action: #selector(performAction))

        viewController.navigationItem.rightBarButtonItem = item
        navBarButtonItem = item
    }
}

// MARK: Events

private extension NavButtonComponent {
    enum Event: String { case connect }
}

// MARK: Message data

private extension NavButtonComponent {
    struct MessageData: Decodable {
        let title: String
    }
}

Version data entries

18 entries across 9 versions & 1 rubygems

Version Path
turbo-native-initializer-0.0.19 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.19 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.18 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.18 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.17 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.17 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.16 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.16 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.15 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.15 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.14 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.14 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.13 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.13 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.12 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.12 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.11 lib/turbo_native_initializer/templates/ios_tabs/TurboNativeProject/Strada/NavButtonComponent.swift
turbo-native-initializer-0.0.11 lib/turbo_native_initializer/templates/ios_stack/TurboNativeProject/Strada/NavButtonComponent.swift