Skip to content

Commit fecae91

Browse files
committed
Export event args types from Types.tsx as well so they can be mentioned in apps
1 parent 327b300 commit fecae91

File tree

7 files changed

+926
-421
lines changed

7 files changed

+926
-421
lines changed

package/Codegen/TSProps.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public virtual string TransformText()
6060

6161
#line default
6262
#line hidden
63-
this.Write("export namespace ");
63+
this.Write("export namespace Native");
6464

6565
#line 32 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
6666
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
@@ -74,7 +74,7 @@ public virtual string TransformText()
7474

7575
#line default
7676
#line hidden
77-
this.Write("export type ");
77+
this.Write("export type Native");
7878

7979
#line 34 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
8080
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(t)));
@@ -335,7 +335,7 @@ public virtual string TransformText()
335335
this.Write("?: (event: NativeSyntheticEvent<");
336336

337337
#line 80 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
338-
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetEventArgsTSName(evt)));
338+
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetEventArgsTSName(evt, "Native")));
339339

340340
#line default
341341
#line hidden

package/Codegen/TSProps.tt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export type TypedEvent<TArgs> = {
2929
<# foreach (var t in Util.eventArgsTypes) {
3030
var ns = Util.GetTSNamespace(t);
3131
if (ns != "") { #>
32-
export namespace <#= ns #> {
32+
export namespace Native<#= ns #> {
3333
<# } #>
34-
export type <#= Util.ToJsName(t) #> = {
34+
export type Native<#= Util.ToJsName(t) #> = {
3535
<# foreach (var m in Util.GetEventArgsMethods(t.GetFullName())) { #>
3636
<#= m #>(<#= Util.GetEventArgsMethodArgs(t, m) #>): <#= Util.GetEventArgsMethodReturnType(t, m) #>
3737
<# }
@@ -77,7 +77,7 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) { #>
7777
<#= Util.ToJsName(attachedDP) #>?: <#= Util.GetTypeScriptType(attachedDP) #>; // attached property
7878
<# }
7979
foreach (var evt in type.GetEvents()) { #>
80-
on<#= evt.GetName() #>?: (event: NativeSyntheticEvent<<#= Util.GetEventArgsTSName(evt) #>>) => void;
80+
on<#= evt.GetName() #>?: (event: NativeSyntheticEvent<<#= Util.GetEventArgsTSName(evt, "Native") #>>) => void;
8181
<# }
8282
foreach (var evt in SyntheticEvents.Where(e => type == e.DeclaringType)) { #>
8383
on<#= evt.Name #>?: (event: NativeSyntheticEvent<<#= Util.GetTypeScriptType(evt) #>>) => void;

package/Codegen/TSTypes.cs

Lines changed: 116 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ------------------------------------------------------------------------------
22
// <auto-generated>
33
// This code was generated by a tool.
4-
// Runtime Version: 16.0.0.0
4+
// Runtime Version: 17.0.0.0
55
//
66
// Changes to this file may cause incorrect behavior and will be lost if
77
// the code is regenerated.
@@ -18,8 +18,8 @@ namespace Codegen
1818
/// Class to produce the template output
1919
/// </summary>
2020

21-
#line 1 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
22-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
21+
#line 1 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
22+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")]
2323
public partial class TSTypes : TSTypesBase
2424
{
2525
#line hidden
@@ -30,44 +30,65 @@ public virtual string TransformText()
3030
{
3131
this.Write("\r\n/*************************************************************\r\nTHIS FILE WAS A" +
3232
"UTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY\r\n********************************" +
33-
"******************************/\r\n\r\nimport type {\r\n");
33+
"******************************/\r\n\r\nimport type {\r\n // Controls\r\n");
3434

35-
#line 12 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
35+
#line 13 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
3636
foreach (var type in Types.Where(t => Util.HasCtor(t) && Util.GetTSNamespace(t) == "")) {
3737

3838
#line default
3939
#line hidden
4040
this.Write(" ");
4141

42-
#line 13 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
42+
#line 14 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
4343
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetNativePropsName(type)));
4444

4545
#line default
4646
#line hidden
4747
this.Write(",\r\n");
4848

49-
#line 14 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
49+
#line 15 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
50+
}
51+
52+
#line default
53+
#line hidden
54+
this.Write("\r\n // EventArgs\r\n");
55+
56+
#line 18 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
57+
foreach (var type in Util.eventArgsTypes.Where(t => Util.GetTSNamespace(t) == "")) {
58+
59+
#line default
60+
#line hidden
61+
this.Write(" Native");
62+
63+
#line 19 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
64+
this.Write(this.ToStringHelper.ToStringWithCulture(type.GetName()));
65+
66+
#line default
67+
#line hidden
68+
this.Write(",\r\n");
69+
70+
#line 20 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
5071
}
5172

5273
#line default
5374
#line hidden
5475
this.Write("} from \'./Props\';\r\n\r\n");
5576

56-
#line 17 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
77+
#line 23 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
5778
foreach (var ns in Types.Where(t => Util.HasCtor(t) && Util.GetTSNamespace(t) != "").Select(t => Util.GetTSNamespace(t)).Distinct()) {
5879

5980
#line default
6081
#line hidden
6182
this.Write("import type { Native");
6283

63-
#line 18 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
84+
#line 24 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
6485
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
6586

6687
#line default
6788
#line hidden
6889
this.Write(" } from \'./Props\';\r\n");
6990

70-
#line 19 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
91+
#line 25 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
7192
}
7293

7394
#line default
@@ -83,7 +104,7 @@ public virtual string TransformText()
83104
84105
");
85106

86-
#line 29 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
107+
#line 35 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
87108

88109
foreach (var type in Types.Where(t => Util.HasCtor(t))) {
89110
var ns = Util.GetTSNamespace(type);
@@ -93,119 +114,185 @@ public virtual string TransformText()
93114
#line hidden
94115
this.Write("export namespace ");
95116

96-
#line 33 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
117+
#line 39 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
97118
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
98119

99120
#line default
100121
#line hidden
101122
this.Write(" {\r\n");
102123

103-
#line 34 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
124+
#line 40 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
104125
}
105126

106127
#line default
107128
#line hidden
108129
this.Write("export type ");
109130

110-
#line 35 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
131+
#line 41 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
111132
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
112133

113134
#line default
114135
#line hidden
115136
this.Write("Props = Omit<");
116137

117-
#line 35 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
138+
#line 41 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
118139
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetNativePropsName(type)));
119140

120141
#line default
121142
#line hidden
122143
this.Write(", \'type\'>;\r\n\r\nexport class ");
123144

124-
#line 37 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
145+
#line 43 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
125146
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
126147

127148
#line default
128149
#line hidden
129150
this.Write(" extends React.Component<");
130151

131-
#line 37 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
152+
#line 43 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
132153
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
133154

134155
#line default
135156
#line hidden
136157
this.Write("Props> {\r\n render() {\r\n return <NativeXamlControl {...this.props} type=\'");
137158

138-
#line 39 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
159+
#line 45 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
139160
this.Write(this.ToStringHelper.ToStringWithCulture(type.GetFullName()));
140161

141162
#line default
142163
#line hidden
143164
this.Write("\' />;\r\n }\r\n");
144165

145-
#line 41 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
166+
#line 47 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
146167
foreach (var command in Util.GetCommands(type.GetFullName())) {
147168

148169
#line default
149170
#line hidden
150171
this.Write(" static ");
151172

152-
#line 42 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
173+
#line 48 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
153174
this.Write(this.ToStringHelper.ToStringWithCulture(command.Name));
154175

155176
#line default
156177
#line hidden
157178
this.Write("(ref: React.MutableRefObject<");
158179

159-
#line 42 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
180+
#line 48 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
160181
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
161182

162183
#line default
163184
#line hidden
164185
this.Write(">, args: ");
165186

166-
#line 42 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
187+
#line 48 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
167188
this.Write(this.ToStringHelper.ToStringWithCulture(command.TSArgTypes != null ? command.TSArgTypes : "any[]"));
168189

169190
#line default
170191
#line hidden
171192
this.Write(") {\r\n const tag = findNodeHandle(ref.current);\r\n UIManager.dispatchViewMana" +
172193
"gerCommand(tag, xamlCommands.");
173194

174-
#line 44 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
195+
#line 50 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
175196
this.Write(this.ToStringHelper.ToStringWithCulture(command.Name));
176197

177198
#line default
178199
#line hidden
179200
this.Write(", ");
180201

181-
#line 44 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
202+
#line 50 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
182203
this.Write(this.ToStringHelper.ToStringWithCulture(command.TSArgTypes != null ? "[args]" : "args"));
183204

184205
#line default
185206
#line hidden
186207
this.Write(");\r\n }\r\n");
187208

188-
#line 46 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
209+
#line 52 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
189210
}
190211

191212
#line default
192213
#line hidden
193214
this.Write("};\r\n");
194215

195-
#line 48 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
216+
#line 54 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
217+
if (ns != "") {
218+
219+
#line default
220+
#line hidden
221+
this.Write("}\r\n");
222+
223+
#line 56 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
224+
}
225+
226+
#line default
227+
#line hidden
228+
229+
#line 57 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
230+
}
231+
232+
#line default
233+
#line hidden
234+
this.Write("\r\n");
235+
236+
#line 59 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
237+
foreach (var ea in Util.eventArgsTypes) {
238+
var ns = Util.GetTSNamespace(ea);
239+
if (ns != "") {
240+
241+
#line default
242+
#line hidden
243+
this.Write("export namespace ");
244+
245+
#line 62 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
246+
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
247+
248+
#line default
249+
#line hidden
250+
this.Write(" {\r\n");
251+
252+
#line 63 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
253+
254+
}
255+
256+
257+
#line default
258+
#line hidden
259+
this.Write("export type ");
260+
261+
#line 66 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
262+
this.Write(this.ToStringHelper.ToStringWithCulture(ea.GetName()));
263+
264+
#line default
265+
#line hidden
266+
this.Write(" = ");
267+
268+
#line 66 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
269+
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetEventArgsTSType(ea, "Native")));
270+
271+
#line default
272+
#line hidden
273+
this.Write("; // ");
274+
275+
#line 66 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
276+
this.Write(this.ToStringHelper.ToStringWithCulture(ea.GetFullName()));
277+
278+
#line default
279+
#line hidden
280+
this.Write(" \r\n");
281+
282+
#line 67 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
196283
if (ns != "") {
197284

198285
#line default
199286
#line hidden
200287
this.Write("}\r\n");
201288

202-
#line 50 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
289+
#line 69 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
203290
}
204291

205292
#line default
206293
#line hidden
207294

208-
#line 51 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
295+
#line 70 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
209296
}
210297

211298
#line default
@@ -220,7 +307,7 @@ public virtual string TransformText()
220307
/// <summary>
221308
/// Base class for this transformation
222309
/// </summary>
223-
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
310+
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "17.0.0.0")]
224311
public class TSTypesBase
225312
{
226313
#region Fields

package/Codegen/TSTypes.tt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY
99
**************************************************************/
1010

1111
import type {
12+
// Controls
1213
<# foreach (var type in Types.Where(t => Util.HasCtor(t) && Util.GetTSNamespace(t) == "")) { #>
1314
<#= Util.GetNativePropsName(type) #>,
1415
<# } #>
16+
17+
// EventArgs
18+
<# foreach (var type in Util.eventArgsTypes.Where(t => Util.GetTSNamespace(t) == "")) { #>
19+
Native<#= type.GetName() #>,
20+
<# } #>
1521
} from './Props';
1622

1723
<# foreach (var ns in Types.Where(t => Util.HasCtor(t) && Util.GetTSNamespace(t) != "").Select(t => Util.GetTSNamespace(t)).Distinct()) { #>
@@ -49,3 +55,16 @@ export class <#= Util.ToJsName(type) #> extends React.Component<<#= Util.ToJsNam
4955
}
5056
<# } #>
5157
<# } #>
58+
59+
<# foreach (var ea in Util.eventArgsTypes) {
60+
var ns = Util.GetTSNamespace(ea);
61+
if (ns != "") { #>
62+
export namespace <#= ns #> {
63+
<#
64+
}
65+
#>
66+
export type <#= ea.GetName() #> = <#= Util.GetEventArgsTSType(ea, "Native") #>; // <#= ea.GetFullName() #>
67+
<# if (ns != "") { #>
68+
}
69+
<# } #>
70+
<# } #>

0 commit comments

Comments
 (0)