-
-
Notifications
You must be signed in to change notification settings - Fork 122
/
DW.AppleIDButton.iOS.pas
133 lines (112 loc) · 4.26 KB
/
DW.AppleIDButton.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
unit DW.AppleIDButton.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
uses
// RTL
System.TypInfo,
// iOS
iOSapi.Foundation,
// FMX
FMX.Presentation.iOS, FMX.Presentation.Messages, FMX.Controls.Model,
// DW
DW.AppleIDButton, DW.iOSapi.AuthenticationServices;
type
IAppleIDButton = interface(ASAuthorizationAppleIDButton)
['{332B340D-21DF-4C0E-86A5-B3418ED3D9FF}']
procedure ButtonClicked(sender: Pointer); cdecl;
end;
TiOSAppleIDButton = class(TiOSNativeControl)
private
function GetModel: TAppleIDButtonModel;
function GetView: ASAuthorizationAppleIDButton;
protected
function DefineModelClass: TDataModelClass; override;
function GetObjectiveCClass: PTypeInfo; override;
procedure InitView; override;
procedure MMSetButtonStyle(var AMessage: TDispatchMessageWithValue<TAppleIDButtonStyle>); message MM_SET_BUTTON_STYLE;
procedure MMSetButtonType(var AMessage: TDispatchMessageWithValue<TAppleIDButtonType>); message MM_SET_BUTTON_TYPE;
procedure MMSetCornerRadius(var AMessage: TDispatchMessageWithValue<Double>); message MM_SET_CORNER_RADIUS;
public
{ IAppleIDButton }
procedure ButtonClicked(sender: Pointer); cdecl;
public
constructor Create; override;
property Model: TAppleIDButtonModel read GetModel;
property View: ASAuthorizationAppleIDButton read GetView;
end;
implementation
uses
// iOS
iOSapi.UIKit,
// FMX
FMX.Presentation.Factory, FMX.Controls,
// DW
DW.OSLog,
DW.AuthenticationServices.iOS;
{ TiOSAppleIDButton }
constructor TiOSAppleIDButton.Create;
begin
inherited;
RegisterNativeEventHandler('ButtonClicked:', UIControlEventTouchDown);
end;
function TiOSAppleIDButton.DefineModelClass: TDataModelClass;
begin
Result := TAppleIDButtonModel;
end;
function TiOSAppleIDButton.GetModel: TAppleIDButtonModel;
begin
Result := inherited GetModel<TAppleIDButtonModel>;
end;
function TiOSAppleIDButton.GetObjectiveCClass: PTypeInfo;
begin
Result := TypeInfo(IAppleIDButton);
end;
function TiOSAppleIDButton.GetView: ASAuthorizationAppleIDButton;
begin
Result := inherited GetView<ASAuthorizationAppleIDButton>;
end;
procedure TiOSAppleIDButton.InitView;
const
cButtonStyles: array[TAppleIDButtonStyle] of ASAuthorizationAppleIDButtonStyle = (
ASAuthorizationAppleIDButtonStyleWhite, ASAuthorizationAppleIDButtonStyleWhiteOutline, ASAuthorizationAppleIDButtonStyleBlack
);
cButtonTypes: array[TAppleIDButtonType] of ASAuthorizationAppleIDButtonType = (
ASAuthorizationAppleIDButtonTypeSignIn, ASAuthorizationAppleIDButtonTypeContinue, ASAuthorizationAppleIDButtonTypeSignUp
);
var
LViewPtr: Pointer;
begin
LViewPtr := View.initWithAuthorizationButtonType(cButtonTypes[Model.ButtonType], cButtonStyles[Model.ButtonStyle]);
if GetObjectID <> LViewPtr then
UpdateObjectID(LViewPtr);
end;
procedure TiOSAppleIDButton.MMSetButtonStyle(var AMessage: TDispatchMessageWithValue<TAppleIDButtonStyle>);
begin
InitView;
end;
procedure TiOSAppleIDButton.MMSetButtonType(var AMessage: TDispatchMessageWithValue<TAppleIDButtonType>);
begin
InitView;
end;
procedure TiOSAppleIDButton.MMSetCornerRadius(var AMessage: TDispatchMessageWithValue<Double>);
begin
View.setCornerRadius(AMessage.Value);
end;
procedure TiOSAppleIDButton.ButtonClicked(sender: Pointer);
begin
TAuthenticationServices.Current.RequestAuthorization;
end;
initialization
TPresentationProxyFactory.Current.Register(TAppleIDButton, TControlType.Platform, TiOSPresentationProxy<TiOSAppleIDButton>);
finalization
TPresentationProxyFactory.Current.Unregister(TAppleIDButton, TControlType.Platform, TiOSPresentationProxy<TiOSAppleIDButton>);
end.