async Task <ProjectFile> CreateBundleView(FigmaBundleViewBase figmaBundleView, Project currentProject, IFigmaFileProvider fileProvider, bool translateStrings) { var bundle = figmaBundleView.Bundle; await fileProvider.LoadAsync(bundle.DocumentFilePath); var converters = NativeControlsContext.Current.GetConverters(); var codePropertyConverter = NativeControlsContext.Current.GetCodePropertyConverter(); var codeRendererService = new NativeViewCodeService(fileProvider, converters, codePropertyConverter); figmaBundleView.Generate(outputDirectory, codeRendererService, namesSpace: bundle.Namespace, translateStrings: translateStrings); var partialDesignerClassFilePath = Path.Combine(outputDirectory, figmaBundleView.PartialDesignerClassName); var publicCsClassFilePath = Path.Combine(outputDirectory, figmaBundleView.PublicCsClassName); var designerProjectFile = currentProject.AddFile(partialDesignerClassFilePath); var csProjectFile = currentProject.AddFile(publicCsClassFilePath); designerProjectFile.DependsOn = csProjectFile.FilePath; designerProjectFile.Metadata.SetValue(FigmaFile.FigmaPackageId, bundle.FileId); designerProjectFile.Metadata.SetValue(FigmaFile.FigmaNodeId, figmaBundleView.FigmaNode.id); return(csProjectFile); }
public override IView ConvertTo(FigmaNode currentNode, ProcessedNode parentNode, FigmaRendererService rendererService) { string title = ""; var frame = (FigmaFrame)currentNode; var nativeView = new FakeWindowView(title); nativeView.LiveButtonAlwaysVisible = LiveButtonAlwaysVisible; nativeView.Configure(currentNode); var view = new View(nativeView); var windowComponent = currentNode.GetDialogInstanceFromParentContainer(); if (windowComponent != null) { var optionsNode = windowComponent.Options(); if (optionsNode is IFigmaNodeContainer figmaNodeContainer) { nativeView.CloseButtonHidden = (figmaNodeContainer.HasChildrenVisible("close") == false); nativeView.MinButtonHidden = (figmaNodeContainer.HasChildrenVisible("min") == false); nativeView.MaxButtonHidden = (figmaNodeContainer.HasChildrenVisible("max") == false); var titleText = (FigmaText)optionsNode.GetChildren().FirstOrDefault(s => s.name == "title" && s.visible); if (titleText != null) { nativeView.Title = titleText.characters; } } } nativeView.LiveButton.Activated += async(s, e) => { var window = new Window(view.Allocation); LivePreviewLoading?.Invoke(this, EventArgs.Empty); await newWindowProvider.LoadAsync(rendererService.FileProvider.File); var secondaryRender = new NativeViewRenderingService(newWindowProvider); var options = new FigmaViewRendererServiceOptions() { GenerateMainView = false }; secondaryRender.RenderInWindow(window, currentNode, options); var mainNodes = currentNode.GetChildren() .ToArray(); ProcessedNode[] processedNodes = secondaryRender.GetProcessedNodes(mainNodes); var layoutManager = new StoryboardLayoutManager() { UsesConstraints = true }; layoutManager.Run(processedNodes, window.Content, secondaryRender); var nativeWindow = (NSWindow)window.NativeObject; nativeWindow.Appearance = nativeView.EffectiveAppearance; nativeWindow.ContentMinSize = nativeWindow.ContentView.Frame.Size; nativeWindow.Center(); nativeWindow.MakeKeyAndOrderFront(null); LivePreviewLoaded?.Invoke(this, EventArgs.Empty); }; return(view); }