Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
UIKitAdapter.hpp
Go to the documentation of this file.
1#pragma once
2
34
36#include "aria/subscription.hpp"
37
38#import <UIKit/UIKit.h>
39
40#include <cstdint>
41#include <functional>
42#include <memory>
43#include <stdexcept>
44#include <string>
45#include <string_view>
46
47// ─── ObjC bridging targets / delegates ──────────────────────────────────
48
49@interface AriaUIClickTarget : NSObject
50- (instancetype)initWithCallback:(std::function<void()>)cb;
51- (void)fire:(id)sender;
52@end
53
54@interface AriaUIToggleTarget : NSObject
55- (instancetype)initWithCallback:(std::function<void(bool)>)cb;
56- (void)fire:(id)sender;
57@end
58
59@interface AriaUIStepperTarget : NSObject
60- (instancetype)initWithCallback:(std::function<void(int)>)cb;
61- (void)fire:(id)sender;
62@end
63
64@interface AriaUISliderTarget : NSObject
65- (instancetype)initWithCallback:(std::function<void(double)>)cb;
66- (void)fire:(id)sender;
67@end
68
69@interface AriaUITextTarget : NSObject
70- (instancetype)initWithCallback:(std::function<void(std::string_view)>)cb;
71- (void)fire:(id)sender;
72@end
73
75
76// ─── View wrapper ───────────────────────────────────────────────────────
77
79public:
80 explicit UIKitView(UIView* view) : view_(view) {}
81 ~UIKitView() override {
82 // Fire destroy while UIView* is still alive so BindingEngine
83 // can erase its bucket before our storage is reclaimed.
85 }
86
87 [[nodiscard]] std::string_view kind() const noexcept override { return "uikit"; }
88 [[nodiscard]] UIView* native() const noexcept { return view_; }
89
90 template<class T>
91 [[nodiscard]] T* as() const { return static_cast<T*>(view_); }
92
93private:
94 UIView* __strong view_;
95};
96
97// ─── Adapter ────────────────────────────────────────────────────────────
98
100public:
102 ~UIKitAdapter() override;
103
104 UIKitAdapter(const UIKitAdapter&) = delete;
106
107 [[nodiscard]] std::string_view platform_name() const noexcept override {
108 return "uikit";
109 }
110
111 // ── Handle → IView ──────────────────────────────────────────────────
137 [[nodiscard]] UIKitView& view_for(UIView* view);
138
144 void release_view(UIView* view) noexcept;
145
146 void set_text(::aria::binding::IView& v, std::string_view text) override;
147 [[nodiscard]] std::string get_text(::aria::binding::IView& v) override;
149 std::function<void(std::string_view)> cb) override;
150
151 void set_bool(::aria::binding::IView& v, bool value) override;
154 std::function<void(bool)> cb) override;
155
156 void set_int(::aria::binding::IView& v, int value) override;
159 std::function<void(int)> cb) override;
160
161 void set_int64(::aria::binding::IView& v, std::int64_t value) override;
162 [[nodiscard]] std::int64_t get_int64(::aria::binding::IView& v) override;
164 std::function<void(std::int64_t)> cb) override;
165
166 void set_uint64(::aria::binding::IView& v, std::uint64_t value) override;
167 [[nodiscard]] std::uint64_t get_uint64(::aria::binding::IView& v) override;
169 std::function<void(std::uint64_t)> cb) override;
170
171 void set_float(::aria::binding::IView& v, float value) override;
174 std::function<void(float)> cb) override;
175
176 void set_double(::aria::binding::IView& v, double value) override;
179 std::function<void(double)> cb) override;
180
181 void set_visible(::aria::binding::IView& v, bool visible) override;
182 void set_enabled(::aria::binding::IView& v, bool enabled) override;
183
185 std::function<void()> cb) override;
186
187private:
188 struct Impl;
189 std::unique_ptr<Impl> p_;
190};
191
192} // namespace aria::adapters::uikit
193
194// ─── Backwards-compat aliases ───────────────────────────────────────────
195
198
199@compatibility_alias UIKitClickWrapper AriaUIClickTarget;
::aria::adapters::uikit::UIKitAdapter UIKitAdapter
Definition UIKitAdapter.hpp:196
::aria::adapters::uikit::UIKitView UIKitView
Definition UIKitAdapter.hpp:197
RAII handle to a single subscription.
Definition subscription.hpp:44
Definition UIKitAdapter.hpp:99
UIKitAdapter & operator=(const UIKitAdapter &)=delete
::aria::Subscription on_double_changed(::aria::binding::IView &v, std::function< void(double)> cb) override
::aria::Subscription on_int64_changed(::aria::binding::IView &v, std::function< void(std::int64_t)> cb) override
void set_visible(::aria::binding::IView &v, bool visible) override
float get_float(::aria::binding::IView &v) override
std::string_view platform_name() const noexcept override
Definition UIKitAdapter.hpp:107
::aria::Subscription on_bool_changed(::aria::binding::IView &v, std::function< void(bool)> cb) override
double get_double(::aria::binding::IView &v) override
::aria::Subscription on_click(::aria::binding::IView &v, std::function< void()> cb) override
std::uint64_t get_uint64(::aria::binding::IView &v) override
void set_uint64(::aria::binding::IView &v, std::uint64_t value) override
void set_enabled(::aria::binding::IView &v, bool enabled) override
::aria::Subscription on_text_changed(::aria::binding::IView &v, std::function< void(std::string_view)> cb) override
UIKitAdapter(const UIKitAdapter &)=delete
std::string get_text(::aria::binding::IView &v) override
void set_int64(::aria::binding::IView &v, std::int64_t value) override
void release_view(UIView *view) noexcept
Drop the cached UIKitView for view, if any.
UIKitView & view_for(UIView *view)
Wrap a native UIView* as an IView owned by this adapter.
void set_int(::aria::binding::IView &v, int value) override
void set_double(::aria::binding::IView &v, double value) override
void set_text(::aria::binding::IView &v, std::string_view text) override
::aria::Subscription on_uint64_changed(::aria::binding::IView &v, std::function< void(std::uint64_t)> cb) override
bool get_bool(::aria::binding::IView &v) override
void set_float(::aria::binding::IView &v, float value) override
void set_bool(::aria::binding::IView &v, bool value) override
::aria::Subscription on_int_changed(::aria::binding::IView &v, std::function< void(int)> cb) override
int get_int(::aria::binding::IView &v) override
std::int64_t get_int64(::aria::binding::IView &v) override
::aria::Subscription on_float_changed(::aria::binding::IView &v, std::function< void(float)> cb) override
Definition UIKitAdapter.hpp:78
T * as() const
Definition UIKitAdapter.hpp:91
std::string_view kind() const noexcept override
Definition UIKitAdapter.hpp:87
~UIKitView() override
Definition UIKitAdapter.hpp:81
UIKitView(UIView *view)
Definition UIKitAdapter.hpp:80
UIView * native() const noexcept
Definition UIKitAdapter.hpp:88
Abstract platform adapter — knows how to read/write/observe widgets.
Definition view_adapter.hpp:80
Abstract platform widget reference.
Definition view_adapter.hpp:28
void fire_destroy_() noexcept
Invoked by ~IView() to fan out the notification — this is the last-resort trigger.
Definition UIKitAdapter.hpp:74
Definition validation_key.hpp:110