This commit is contained in:
Alexander Sklar 2021-11-12 18:37:00 -08:00
Родитель 51780072ef
Коммит e68ff1e3d9
21 изменённых файлов: 281 добавлений и 151 удалений

Просмотреть файл

@ -6,7 +6,7 @@
* @flow strict-local
*/
import React from 'react';
import React, {useRef} from 'react';
import type {Node} from 'react';
import {
SafeAreaView,
@ -19,7 +19,10 @@ import {
} from 'react-native';
import {
TextBlock
TextBox,
MenuFlyout,
MenuFlyoutItem,
TextBlock,
} from 'react-native-xaml';
import {
Colors,
@ -62,6 +65,11 @@ const App: () => Node = () => {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
const menu = useRef<MenuFlyout>(null);
const _tbRef = React.useRef<TextBlock>(null);
const [x, setX] = React.useState(100);
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
@ -72,8 +80,28 @@ const App: () => Node = () => {
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<TextBlock text="Hello" />
}}>
<TextBox
text={x}
onBeforeTextChanging={e => {
setX(e.nativeEvent.args.newText);
}}
/>
<TextBlock
text="Hello"
onTapped={e => {
MenuFlyout.ShowAt(menu, {point: {x: x, y: 42}});
}}
ref={t => {
_tbRef.current = t;
}}>
<MenuFlyout
ref={m => {
menu.current = m;
}}>
<MenuFlyoutItem text="menu option" />
</MenuFlyout>
</TextBlock>
</View>
</ScrollView>
</SafeAreaView>

Просмотреть файл

@ -136,6 +136,7 @@ namespace Codegen
public class Command
{
public string Name { get; set; }
public string TSArgTypes { get; set; }
}
public partial class VersionHeader

Просмотреть файл

@ -64,7 +64,12 @@ namespace Codegen
var commands = new List<Command>();
foreach (var c in entry.Value.EnumerateArray())
{
commands.Add(new Command { Name = c.GetProperty("name").GetString() });
var command = new Command { Name = c.GetProperty("name").GetString() };
if (c.TryGetProperty("args", out var value))
{
command.TSArgTypes = ConvertJSONToTSType(value);
}
commands.Add(command);
}
Util.commands[GetTypeNameFromJsonProperty(entry)] = commands;
}
@ -373,6 +378,29 @@ namespace Codegen
PrintVerbose($"Done in {(DateTime.Now - start).TotalSeconds} s");
}
private string ConvertJSONToTSType(JsonElement value)
{
switch (value.ValueKind)
{
case JsonValueKind.String:
return "string";
case JsonValueKind.Number:
return "number";
case JsonValueKind.Object:
{
var tsType = "{ ";
foreach (var entry in value.EnumerateObject())
{
tsType += $"{entry.Name}: {entry.Value.GetString()}, ";
}
tsType += " }";
return tsType;
}
default:
throw new ArgumentException("Unexpected JSON type");
}
}
private void DiscoverAttachedProperties(MrLoadContext context, IEnumerable<MrType> types)
{
var attached = new List<MrProperty>();

Просмотреть файл

@ -18,7 +18,7 @@ namespace Codegen
/// Class to produce the template output
/// </summary>
#line 1 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
public partial class TSEnums : TSEnumsBase
{
@ -28,135 +28,141 @@ namespace Codegen
/// </summary>
public virtual string TransformText()
{
this.Write("\r\n/*************************************************************\r\nTHIS FILE WAS A" +
"UTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY\r\n********************************" +
"******************************/\r\n\r\n");
this.Write("\n");
this.Write("\n");
this.Write("\n");
this.Write("\n");
this.Write("\n\n/*************************************************************\nTHIS FILE WAS AU" +
"TOMATICALLY GENERATED, DO NOT MODIFY MANUALLY\n**********************************" +
"****************************/\n\n");
#line 11 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
foreach (var enumType in Util.enumsToGenerateConvertersFor) {
var ns = Util.GetTSNamespace(enumType);
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
foreach (var enumType in Util.enumsToGenerateConvertersFor) {
var ns = Util.GetTSNamespace(enumType);
if (ns != "") {
#line default
#line hidden
this.Write("export namespace ");
this.Write("\nexport namespace ");
#line 14 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
#line default
#line hidden
this.Write("Enums {\r\n");
this.Write("Enums {\n");
#line 15 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
}
#line default
#line hidden
this.Write("export enum ");
this.Write("\nexport enum ");
#line 16 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(enumType)));
#line default
#line hidden
this.Write(" {\r\n");
this.Write(" {\n");
#line 17 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
foreach (var value in enumType.GetFields().Skip(1)) {
#line default
#line hidden
this.Write(" ");
this.Write("\n ");
#line 18 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(value.GetName()));
#line default
#line hidden
this.Write(" = ");
#line 18 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture((int)value.GetConstantValue(out System.Reflection.Metadata.ConstantTypeCode typeCode)));
#line default
#line hidden
this.Write(",\r\n");
this.Write(",\n");
#line 19 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
}
#line default
#line hidden
this.Write("}\r\n");
this.Write("}\n");
#line 20 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
if (ns != "") {
#line default
#line hidden
this.Write("}\r\n\r\n");
this.Write("\n}\n\n");
#line 23 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
}
#line default
#line hidden
this.Write("\n");
#line 24 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
}
#line default
#line hidden
this.Write("\r\n\r\n");
this.Write("\n\n\n");
#line 27 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
foreach (var enumType in Util.fakeEnums) {
#line default
#line hidden
this.Write("export enum ");
this.Write("\nexport enum ");
#line 28 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(enumType.Name));
#line default
#line hidden
this.Write(" {\r\n");
this.Write(" {\n");
#line 29 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
foreach (var value in enumType.Values) {
#line default
#line hidden
this.Write(" ");
this.Write("\n ");
#line 30 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(value.Key));
#line default
#line hidden
this.Write(" = ");
#line 30 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(value.Value));
#line default
#line hidden
this.Write(",\r\n");
this.Write(",\n");
#line 31 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
}
#line default
#line hidden
this.Write("}\r\n\r\n");
this.Write("\n}\n\n");
#line 34 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSEnums.tt"
}
#line default
#line hidden
this.Write("\n");
return this.GenerationEnvironment.ToString();
}
}

Просмотреть файл

@ -18,7 +18,7 @@ namespace Codegen
/// Class to produce the template output
/// </summary>
#line 1 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TSProps.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
public partial class TSProps : TSPropsBase
{
@ -42,16 +42,18 @@ export type GridLength = number | '*' | 'auto' | `${number}*`;
export type CornerRadius = number | { topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number};
export type Point = { x: number, y: number };
");
#line 20 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 22 "F:\react-native-xaml\package\Codegen\TSProps.tt"
var derived = Util.GetDerivedTypes(Types);
foreach (var type in Types) {
#line default
#line hidden
#line 22 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 24 "F:\react-native-xaml\package\Codegen\TSProps.tt"
var ns = Util.GetTSNamespace(type);
if (ns != "") {
@ -59,35 +61,35 @@ if (ns != "") {
#line hidden
this.Write("export namespace Native");
#line 24 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 26 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
#line default
#line hidden
this.Write(" {\r\n");
#line 25 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 27 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
#line default
#line hidden
this.Write("export interface Native");
#line 26 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 28 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
#line default
#line hidden
this.Write("Props extends ");
#line 26 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 28 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetBaseClassProps(type)));
#line default
#line hidden
this.Write(" {\r\n");
#line 27 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 29 "F:\react-native-xaml\package\Codegen\TSProps.tt"
var typeProp = Util.GetJsTypeProperty(type, derived);
if (typeProp != "") {
@ -95,14 +97,14 @@ if (typeProp != "") {
#line hidden
this.Write(" type: ");
#line 29 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 31 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(typeProp));
#line default
#line hidden
this.Write(";\r\n");
#line 30 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 32 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
foreach (var prop in type.GetProperties().Where(p => Util.ShouldEmitPropertyMetadata(p))) {
@ -110,21 +112,21 @@ foreach (var prop in type.GetProperties().Where(p => Util.ShouldEmitPropertyMeta
#line hidden
this.Write(" ");
#line 32 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 34 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(prop)));
#line default
#line hidden
this.Write("?: ");
#line 32 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 34 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetTypeScriptType(prop)));
#line default
#line hidden
this.Write(";\r\n");
#line 33 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 35 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
foreach (var prop in FakeProps.Where(p => type == p.DeclaringType)) {
@ -132,21 +134,21 @@ foreach (var prop in FakeProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" ");
#line 35 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 37 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(prop)));
#line default
#line hidden
this.Write("?: ");
#line 35 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 37 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetTypeScriptType(prop)));
#line default
#line hidden
this.Write("; // synthetic property\r\n");
#line 36 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 38 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
@ -154,28 +156,28 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" /**\r\n * ");
#line 39 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 41 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(prop.Comment));
#line default
#line hidden
this.Write("\r\n */\r\n ");
#line 41 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 43 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(prop.Name)));
#line default
#line hidden
this.Write("?: ");
#line 41 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 43 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetTypeScriptType(prop)));
#line default
#line hidden
this.Write("; // synthetic property\r\n");
#line 42 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 44 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
foreach (var attachedDP in Util.AttachedProperties.Where(p => Properties.Any(sp => sp.Property == p && sp.DeclaringType == type))) {
@ -183,21 +185,21 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" ");
#line 44 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 46 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(attachedDP)));
#line default
#line hidden
this.Write("?: ");
#line 44 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 46 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetTypeScriptType(attachedDP)));
#line default
#line hidden
this.Write("; // attached property\r\n");
#line 45 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 47 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
foreach (var evt in type.GetEvents()) {
@ -205,14 +207,14 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" on");
#line 47 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 49 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(evt.GetName()));
#line default
#line hidden
this.Write("?: (event: NativeSyntheticEvent<undefined>) => void;\r\n");
#line 48 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 50 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
foreach (var evt in SyntheticEvents.Where(e => type == e.DeclaringType)) {
@ -220,48 +222,48 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" on");
#line 50 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 52 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(evt.Name));
#line default
#line hidden
this.Write("?: (event: NativeSyntheticEvent<");
#line 50 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 52 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetTypeScriptType(evt)));
#line default
#line hidden
this.Write(">) => void;\r\n");
#line 51 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 53 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
#line default
#line hidden
this.Write("}\r\n");
#line 53 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 55 "F:\react-native-xaml\package\Codegen\TSProps.tt"
if (ns != "") {
#line default
#line hidden
this.Write("}\r\n");
#line 55 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 57 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
#line default
#line hidden
#line 56 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 58 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
#line default
#line hidden
this.Write("\r\nexport type XamlControlProps =");
#line 58 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 60 "F:\react-native-xaml\package\Codegen\TSProps.tt"
var first = true; foreach (var type in Types) {
if (Util.HasCtor(type) || !type.IsSealed) {
if (!first)
@ -270,7 +272,7 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" | ");
#line 60 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 62 "F:\react-native-xaml\package\Codegen\TSProps.tt"
;
first = false;
@ -280,14 +282,14 @@ foreach (var prop in SyntheticProps.Where(p => type == p.DeclaringType)) {
#line hidden
this.Write(" ");
#line 63 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 65 "F:\react-native-xaml\package\Codegen\TSProps.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetNativePropsName(type)));
#line default
#line hidden
this.Write("\r\n\t");
#line 64 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSProps.tt"
#line 66 "F:\react-native-xaml\package\Codegen\TSProps.tt"
}
}

Просмотреть файл

@ -17,6 +17,8 @@ export type GridLength = number | '*' | 'auto' | `${number}*`;
export type CornerRadius = number | { topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number};
export type Point = { x: number, y: number };
<# var derived = Util.GetDerivedTypes(Types);
foreach (var type in Types) { #>
<# var ns = Util.GetTSNamespace(type);

Просмотреть файл

@ -32,51 +32,58 @@ namespace Codegen
"UTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY\r\n********************************" +
"******************************/\r\n\r\nimport type {\r\n");
#line 12 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 12 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
foreach (var type in Types.Where(t => Util.HasCtor(t) && Util.GetTSNamespace(t) == "")) {
#line default
#line hidden
this.Write(" ");
#line 13 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 13 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetNativePropsName(type)));
#line default
#line hidden
this.Write(",\r\n");
#line 14 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 14 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
}
#line default
#line hidden
this.Write("} from \'./Props\';\r\n\r\n");
#line 17 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 17 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
foreach (var ns in Types.Where(t => Util.HasCtor(t) && Util.GetTSNamespace(t) != "").Select(t => Util.GetTSNamespace(t)).Distinct()) {
#line default
#line hidden
this.Write("import type { Native");
#line 18 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 18 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
#line default
#line hidden
this.Write(" } from \'./Props\';\r\n");
#line 19 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 19 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
}
#line default
#line hidden
this.Write("\r\nimport React from \'react\';\r\nimport { NativeXamlControl } from \'./NativeXamlCont" +
"rol\';\r\nimport { findNodeHandle, UIManager } from \'react-native\';\r\n\r\nconst xamlCo" +
"mmands = UIManager.getViewManagerConfig(\'XamlControl\').Commands;\r\n\r\n");
this.Write(@"
import React from 'react';
import { NativeXamlControl } from './NativeXamlControl';
import { findNodeHandle, UIManager } from 'react-native';
import type { Point } from './Props';
const xamlCommands = UIManager.getViewManagerConfig('XamlControl').Commands;
");
#line 25 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 29 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
foreach (var type in Types.Where(t => Util.HasCtor(t))) {
var ns = Util.GetTSNamespace(type);
@ -86,98 +93,119 @@ if (ns != "") {
#line hidden
this.Write("export namespace ");
#line 29 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 33 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
#line default
#line hidden
this.Write(" {\r\n");
#line 30 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 34 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
}
#line default
#line hidden
this.Write("export type ");
#line 31 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 35 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
#line default
#line hidden
this.Write("Props = Omit<");
#line 31 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 35 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetNativePropsName(type)));
#line default
#line hidden
this.Write(", \'type\'>;\r\n\r\nexport class ");
#line 33 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 37 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
#line default
#line hidden
this.Write(" extends React.Component<");
#line 33 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 37 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
#line default
#line hidden
this.Write("Props> {\r\n render() {\r\n return <NativeXamlControl {...this.props} type=\'");
#line 32 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
#line 39 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(type.GetFullName()));
#line default
#line hidden
this.Write("\' />;\r\n }\r\n");
#line 34 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
#line 41 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
foreach (var command in Util.GetCommands(type.GetFullName())) {
#line default
#line hidden
this.Write(" static ");
#line 35 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
#line 42 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(command.Name));
#line default
#line hidden
this.Write("(ref: React.MutableRefObject<");
#line 33 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 42 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.ToJsName(type)));
#line default
#line hidden
this.Write(">, args: any[]) {\r\n const tag = findNodeHandle(ref.current);\r\n UIManager.di" +
"spatchViewManagerCommand(tag, xamlCommands.");
this.Write(">, args: ");
#line 35 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(type.GetFullName()));
#line 42 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(command.TSArgTypes != null ? command.TSArgTypes : "any[]"));
#line default
#line hidden
this.Write(") {\r\n const tag = findNodeHandle(ref.current);\r\n UIManager.dispatchViewMana" +
"gerCommand(tag, xamlCommands.");
#line 44 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(command.Name));
#line default
#line hidden
this.Write(", ");
#line 44 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(command.TSArgTypes != null ? "[args]" : "args"));
#line default
#line hidden
this.Write(");\r\n }\r\n");
#line 46 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
}
#line default
#line hidden
this.Write("};\r\n");
#line 38 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 48 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
if (ns != "") {
#line default
#line hidden
this.Write("}\r\n");
#line 40 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 50 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
}
#line default
#line hidden
#line 41 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TSTypes.tt"
#line 51 "F:\react-native-xaml\package\Codegen\TSTypes.tt"
}
#line default

Просмотреть файл

@ -22,6 +22,8 @@ import React from 'react';
import { NativeXamlControl } from './NativeXamlControl';
import { findNodeHandle, UIManager } from 'react-native';
import type { Point } from './Props';
const xamlCommands = UIManager.getViewManagerConfig('XamlControl').Commands;
<#
@ -37,9 +39,9 @@ export class <#= Util.ToJsName(type) #> extends React.Component<<#= Util.ToJsNam
return <NativeXamlControl {...this.props} type='<#= type.GetFullName() #>' />;
}
<# foreach (var command in Util.GetCommands(type.GetFullName())) { #>
static <#= command.Name #>(ref: React.MutableRefObject<<#= Util.ToJsName(type) #>>, args: any[]) {
static <#= command.Name #>(ref: React.MutableRefObject<<#= Util.ToJsName(type) #>>, args: <#= command.TSArgTypes != null ? command.TSArgTypes : "any[]" #>) {
const tag = findNodeHandle(ref.current);
UIManager.dispatchViewManagerCommand(tag, xamlCommands.<#= command.Name #>, args);
UIManager.dispatchViewManagerCommand(tag, xamlCommands.<#= command.Name #>, <#= command.TSArgTypes != null ? "[args]" : "args" #>);
}
<# } #>
};

Просмотреть файл

@ -18,7 +18,7 @@ namespace Codegen
/// Class to produce the template output
/// </summary>
#line 1 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
public partial class TypeCreator : TypeCreatorBase
{
@ -31,21 +31,21 @@ namespace Codegen
this.Write("#include \"pch.h\"\r\n#include \"XamlMetadata.h\"\r\n#include \"Crc32Str.h\"\r\n#include <win" +
"string.h>\r\n\r\n");
#line 11 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 11 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
foreach (var ns in Types.Select(x => x.GetNamespace()).Distinct()) {
#line default
#line hidden
this.Write("#include \"winrt/");
#line 12 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 12 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
#line default
#line hidden
this.Write(".h\"\r\n");
#line 13 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 13 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
}
#line default
@ -77,28 +77,28 @@ winrt::Windows::Foundation::IInspectable XamlMetadata::Create(const std::string_
switch (key) {
");
#line 39 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 39 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
foreach (var t in Types.Where(t => Util.GetComposableFactoryType(t) != null)) {
#line default
#line hidden
this.Write(" case COMPILE_TIME_CRC32_STR(\"");
#line 40 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 40 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(t.GetFullName()));
#line default
#line hidden
this.Write("\"): { return ");
#line 40 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 40 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetCppWinRTType(t)));
#line default
#line hidden
this.Write("(); }\r\n");
#line 41 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeCreator.tt"
#line 41 "F:\react-native-xaml\package\Codegen\TypeCreator.tt"
}
#line default

Просмотреть файл

@ -18,7 +18,7 @@ namespace Codegen
/// Class to produce the template output
/// </summary>
#line 1 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
public partial class TypeEnums : TypeEnumsBase
{
@ -32,49 +32,49 @@ namespace Codegen
"S FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY\r\n********************" +
"******************************************/\r\n\r\n");
#line 12 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 12 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
foreach (var p in Util.fakeEnums.Where(p => p.Name.EndsWith("Priority"))) {
#line default
#line hidden
this.Write("enum class ");
#line 13 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 13 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(p.Name));
#line default
#line hidden
this.Write(" {\r\n");
#line 14 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 14 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
foreach (var value in p.Values) {
#line default
#line hidden
this.Write(" ");
#line 15 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 15 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(value.Key));
#line default
#line hidden
this.Write(" = ");
#line 15 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 15 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(value.Value));
#line default
#line hidden
this.Write(",\r\n");
#line 16 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 16 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
}
#line default
#line hidden
this.Write("};\r\n\r\n");
#line 19 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEnums.tt"
#line 19 "F:\react-native-xaml\package\Codegen\TypeEnums.tt"
}
#line default

Просмотреть файл

@ -18,7 +18,7 @@ namespace Codegen
/// Class to produce the template output
/// </summary>
#line 1 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 1 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "16.0.0.0")]
public partial class TypeEvents : TypeEventsBase
{
@ -41,28 +41,28 @@ THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY
");
#line 17 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 17 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
foreach (var ns in Events.Select(p => p.DeclaringType.GetNamespace()).Distinct()) {
#line default
#line hidden
this.Write("#include <winrt/");
#line 18 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 18 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(ns));
#line default
#line hidden
this.Write(".h>\r\n");
#line 19 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 19 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
}
#line default
#line hidden
this.Write("#include <winrt/");
#line 20 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 20 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(XamlNames.XamlNamespace));
#line default
@ -92,14 +92,14 @@ THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY
"AsFE, args);\r\n });\r\n }\r\n};\r\n\r\n/*static*/ const EventInfo EventInfo::xamlEv" +
"entMap[] = {\r\n");
#line 58 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 58 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
foreach (var evt in Events) {
#line default
#line hidden
this.Write(" {\"");
#line 59 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 59 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(evt.GetName()));
#line default
@ -107,21 +107,21 @@ THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY
this.Write("\", [](const EventAttachInfo& eai, bool isWrapped, winrt::event_token token) noexc" +
"ept {\r\n if (const auto& c = DoTheTypeChecking<");
#line 60 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 60 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetCppWinRTType(evt.DeclaringType)));
#line default
#line hidden
this.Write(">(eai.obj, isWrapped)) {\r\n if (!token) {\r\n return c.");
#line 62 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 62 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(evt.GetName()));
#line default
#line hidden
this.Write("([eai] (");
#line 62 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 62 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Util.GetCppWinRTEventSignature(evt)));
#line default
@ -129,7 +129,7 @@ THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY
this.Write(") noexcept {\r\n DispatchTheEvent(eai, sender, args);\r\n });\r\n " +
" } else {\r\n c.");
#line 66 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 66 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(evt.GetName()));
#line default
@ -137,34 +137,34 @@ THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT MODIFY MANUALLY
this.Write("(token);\r\n return winrt::event_token{ -1 };\r\n }\r\n }\r\n return wi" +
"nrt::event_token{0};\r\n } },\r\n");
#line 72 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 72 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
}
#line default
#line hidden
#line 73 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 73 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
foreach (var evt in SyntheticEvents) {
#line default
#line hidden
this.Write(" {\"");
#line 74 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 74 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(evt.Name));
#line default
#line hidden
this.Write("\", nullptr /* synthetic event */},\r\n");
#line 75 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 75 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
}
#line default
#line hidden
this.Write("};\r\n\r\nstatic_assert(ARRAYSIZE(EventInfo::xamlEventMap) == ");
#line 78 "C:\Users\asklar\source\repos\react-native-xaml\package\Codegen\TypeEvents.tt"
#line 78 "F:\react-native-xaml\package\Codegen\TypeEvents.tt"
this.Write(this.ToStringHelper.ToStringWithCulture(Events.Count() + SyntheticEvents.Count()));
#line default

Просмотреть файл

@ -335,7 +335,7 @@ void XamlMetadata::PopulateNativeProps(winrt::Windows::Foundation::Collections::
struct XamlCommand {
const char* name;
void (*pfn)(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args) noexcept;
void (*pfn)(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args, const XamlMetadata& xaml) noexcept;
};
");
@ -359,7 +359,7 @@ struct XamlCommand {
#line default
#line hidden
this.Write("Command(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& /" +
"* args */) noexcept;\r\n");
"* args */, const XamlMetadata& xaml) noexcept;\r\n");
#line 79 "F:\react-native-xaml\package\Codegen\TypeProperties.tt"
} }

Просмотреть файл

@ -70,12 +70,12 @@ void XamlMetadata::PopulateNativeProps(winrt::Windows::Foundation::Collections::
struct XamlCommand {
const char* name;
void (*pfn)(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args) noexcept;
void (*pfn)(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args, const XamlMetadata& xaml) noexcept;
};
<# foreach (var kv in Util.commands) { #>
<# foreach (var command in kv.Value) { #>
void <#= command.Name #>Command(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& /* args */) noexcept;
void <#= command.Name #>Command(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& /* args */, const XamlMetadata& xaml) noexcept;
<# } } #>
const XamlCommand xamlCommands[] = {

Просмотреть файл

@ -166,6 +166,14 @@
{
"name": "CustomCommand"
}
],
"$xaml.Controls.MenuFlyout": [
{
"name": "ShowAt",
"args": {
"point": "Point"
}
}
]
}
}

Просмотреть файл

@ -12,6 +12,8 @@ export type GridLength = number | '*' | 'auto' | `${number}*`;
export type CornerRadius = number | { topLeft?: number, topRight?: number, bottomLeft?: number, bottomRight?: number};
export type Point = { x: number, y: number };
export namespace NativeWinUI {
export interface NativeAnimatedIconProps extends NativeIconElementProps {
type: 'Microsoft.UI.Xaml.Controls.AnimatedIcon';

Просмотреть файл

@ -182,6 +182,8 @@ import React from 'react';
import { NativeXamlControl } from './NativeXamlControl';
import { findNodeHandle, UIManager } from 'react-native';
import type { Point } from './Props';
const xamlCommands = UIManager.getViewManagerConfig('XamlControl').Commands;
export namespace WinUI {
@ -1163,6 +1165,10 @@ export class MenuFlyout extends React.Component<MenuFlyoutProps> {
render() {
return <NativeXamlControl {...this.props} type='Windows.UI.Xaml.Controls.MenuFlyout' />;
}
static ShowAt(ref: React.MutableRefObject<MenuFlyout>, args: { point: Point, }) {
const tag = findNodeHandle(ref.current);
UIManager.dispatchViewManagerCommand(tag, xamlCommands.ShowAt, [args]);
}
};
export type MenuBarItemFlyoutProps = Omit<NativeMenuBarItemFlyoutProps, 'type'>;

Просмотреть файл

@ -1934,13 +1934,15 @@ void XamlMetadata::PopulateNativeProps(winrt::Windows::Foundation::Collections::
struct XamlCommand {
const char* name;
void (*pfn)(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args) noexcept;
void (*pfn)(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args, const XamlMetadata& xaml) noexcept;
};
void CustomCommandCommand(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& /* args */) noexcept;
void CustomCommandCommand(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& /* args */, const XamlMetadata& xaml) noexcept;
void ShowAtCommand(FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& /* args */, const XamlMetadata& xaml) noexcept;
const XamlCommand xamlCommands[] = {
{ "CustomCommand", CustomCommandCommand},
{ "ShowAt", ShowAtCommand},
};
void XamlMetadata::PopulateCommands(const winrt::Windows::Foundation::Collections::IVector<winrt::hstring>& commands) const {

Просмотреть файл

@ -78,7 +78,7 @@ winrt::Windows::Foundation::IInspectable XamlMetadata::Create(const std::string&
return e;
}
FrameworkElement XamlMetadata::GetFlyoutTarget(winrt::Windows::Foundation::IInspectable flyout) {
FrameworkElement XamlMetadata::GetFlyoutTarget(winrt::Windows::Foundation::IInspectable flyout) const {
auto it = std::find_if(wrapperToWrapped.begin(), wrapperToWrapped.end(), [flyout](auto& entry) {
WrapperInfo wrapperInfo = entry.second;
return wrapperInfo.wrappedObject == flyout;
@ -387,12 +387,11 @@ winrt::fire_and_forget winrt::Microsoft::ReactNative::SetImageSourceForInlineDat
o.SetValue(dp, source);
}
}
void XamlMetadata::DispatchCommand(FrameworkElement const& view, winrt::hstring const& commandId, const winrt::Microsoft::ReactNative::JSValueArray& args) const noexcept {
const std::string name = winrt::to_string(commandId);
auto it = std::find_if(xamlCommands, xamlCommands + std::size(xamlCommands), [name](const XamlCommand& entry) { return Equals(entry.name, name.c_str()); });
if (it != xamlCommands + std::size(xamlCommands)) {
it->pfn(view, args);
it->pfn(view, args, *this);
}
}

Просмотреть файл

@ -228,7 +228,7 @@ struct XamlMetadata : std::enable_shared_from_this<XamlMetadata> {
std::optional<facebook::jsi::Function> m_callFunctionReturnFlushedQueue;
winrt::Microsoft::ReactNative::IReactDispatcher UIDispatcher() const { return m_reactContext.UIDispatcher(); }
FrameworkElement GetFlyoutTarget(winrt::Windows::Foundation::IInspectable wrapper);
FrameworkElement GetFlyoutTarget(winrt::Windows::Foundation::IInspectable wrapper) const;
private:
winrt::Windows::Foundation::IInspectable Create(const std::string_view& typeName) const;

Просмотреть файл

@ -9,6 +9,7 @@
#include <UI.Text.h>
#include "Codegen/EventArgsTypeProperties.g.h"
#include "XamlViewManager.h"
namespace jsi = facebook::jsi;
@ -253,6 +254,21 @@ std::vector<jsi::PropNameID> XamlObject::getPropertyNames(jsi::Runtime& rt) noex
return pnames;
}
void CustomCommandCommand(xaml::FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args) noexcept {
void CustomCommandCommand(xaml::FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args, const XamlMetadata& xaml) noexcept {
OutputDebugStringA("Custom command was called\n");
}
auto ReadPoint(const JSValueObject& o) {
const auto& x = o["x"];
return winrt::Windows::Foundation::Point{ o["x"].AsSingle(), o["y"].AsSingle() };
}
void ShowAtCommand(xaml::FrameworkElement fe, const winrt::Microsoft::ReactNative::JSValueArray& args, const XamlMetadata& xaml) noexcept {
const auto& point = ReadPoint(args[0].GetObjectProperty("point").AsObject());
if (auto menuFlyout = Unwrap<MenuFlyout>(fe)) {
auto target = xaml.GetFlyoutTarget(menuFlyout);
menuFlyout.ShowAt(target, point);
}
OutputDebugStringA("ShowAt ***************\n");
}

Просмотреть файл

@ -105,7 +105,7 @@ namespace winrt::ReactNativeXaml {
// IViewManagerWithCommands
IVectorView<hstring> XamlViewManager::Commands() noexcept {
auto commands = winrt::single_threaded_vector<hstring>();
commands.Append(L"CustomCommand");
m_xamlMetadata->PopulateCommands(commands);
return commands.GetView();
}