forked from DelphiWorlds/Kastri
-
Notifications
You must be signed in to change notification settings - Fork 1
/
DW.NativeButton.iOS.pas
109 lines (91 loc) · 3.32 KB
/
DW.NativeButton.iOS.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
unit DW.NativeButton.iOS;
{*******************************************************}
{ }
{ Kastri }
{ }
{ Delphi Worlds Cross-Platform Library }
{ }
{ Copyright 2020-2024 Dave Nottage under MIT license }
{ which is located in the root folder of this library }
{ }
{*******************************************************}
interface
implementation
uses
// RTL
System.TypInfo, System.Classes, System.SysUtils, System.Types,
// macOS
Macapi.Helpers,
// iOS
iOSapi.UIKit, iOSapi.Foundation,
// FMX
FMX.Presentation.Messages, FMX.Presentation.iOS, FMX.Presentation.Factory, FMX.Controls, FMX.Controls.Presentation, FMX.Controls.Model,
// DW
DW.NativeButton, DW.NativeControl.iOS;
type
INativeButton = interface(UIButton)
['{9A55BD8B-6C46-47DD-9647-0B957EDFAAA7}']
{ Native methods }
function canBecomeFirstResponder: Boolean; cdecl;
procedure touchesBegan(touches: NSSet; withEvent: UIEvent); cdecl;
procedure touchesCancelled(touches: NSSet; withEvent: UIEvent); cdecl;
procedure touchesEnded(touches: NSSet; withEvent: UIEvent); cdecl;
procedure touchesMoved(touches: NSSet; withEvent: UIEvent); cdecl;
{ Handlers }
procedure HandleLongPress(gestureRecognizer: UILongPressGestureRecognizer); cdecl;
end;
TiOSNativeButton = class(TNativeControl)
private
function GetModel: TCustomNativeButtonModel;
function GetView: UIButton;
procedure MMSetText(var AMessage: TDispatchMessageWithValue<string>); message MM_SET_TEXT;
protected
function GetObjectiveCClass: PTypeInfo; override;
function DefineModelClass: TDataModelClass; override;
procedure DoLongPress; override;
public
constructor Create; override;
destructor Destroy; override;
property Model: TCustomNativeButtonModel read GetModel;
property View: UIButton read GetView;
end;
{ TiOSNativeButton }
constructor TiOSNativeButton.Create;
begin
inherited;
View.setUserInteractionEnabled(True);
end;
function TiOSNativeButton.DefineModelClass: TDataModelClass;
begin
Result := TCustomNativeButtonModel;
end;
destructor TiOSNativeButton.Destroy;
begin
//
inherited;
end;
function TiOSNativeButton.GetModel: TCustomNativeButtonModel;
begin
Result := inherited GetModel<TCustomNativeButtonModel>;
end;
function TiOSNativeButton.GetObjectiveCClass: PTypeInfo;
begin
Result := TypeInfo(INativeButton);
end;
function TiOSNativeButton.GetView: UIButton;
begin
Result := inherited GetView<UIButton>;
end;
procedure TiOSNativeButton.MMSetText(var AMessage: TDispatchMessageWithValue<string>);
begin
View.setTitle(StrToNSStr(AMessage.Value), UIControlStateNormal);
end;
procedure TiOSNativeButton.DoLongPress;
begin
Model.DoLongPress;
end;
initialization
TPresentationProxyFactory.Current.Register(TNativeButton, TControlType.Platform, TiOSPresentationProxy<TiOSNativeButton>);
finalization
TPresentationProxyFactory.Current.Unregister(TNativeButton, TControlType.Platform, TiOSPresentationProxy<TiOSNativeButton>);
end.