Skip to content

Unable to create custom Hyperlink using HyperLinkButton and TextBlock #6392

Closed

Description

@vijay-kadam

Microsoft.Reactnative exposes interface IViewManager which only works with Frameworkelement. Also there are no shadow nodes in current 0.63 version. I have codebase which is from 0.59-legacy version but now i want to create custom native component in CS using HyperlinkButton and TextBlock. Here is my component class from 0.59-legacy how can i convert below snippet in 0.63 version.

public class ReactHyperlinkButtonViewManager : BaseControlViewManager<HyperlinkButton, ReactSimpleTextShadowNode>
  {
    public override string Name => "RCTHyperlinkButtonView";

    protected override HyperlinkButton CreateViewInstance(ThemedReactContext reactContext)
    {
      var view = new HyperlinkButton();

      view.Content = new TextBlock();
      return view;
    }



    protected override void AddEventEmitters(ThemedReactContext reactContext, HyperlinkButton view)
    {

    }

    public override void OnDropViewInstance(ThemedReactContext reactContext, HyperlinkButton view)
    {
    }

    private void OnPointerEntered(object sender, RoutedEventArgs e)
    {
    }

    private void OnPointerExited(object sender, RoutedEventArgs e)
    {

    }

    private void OnClick(object sender, RoutedEventArgs e)
    {

    }

    private void OnBlur(object sender, RoutedEventArgs e)
    {
    }

    private void OnFocus(object sender, RoutedEventArgs e)
    {

    }



    public override ReactSimpleTextShadowNode CreateShadowNodeInstance()
    {
      return new ReactSimpleTextShadowNode();
    }

    public override void UpdateExtraData(HyperlinkButton view, object extraData)
    {
      var textNode = extraData as ReactSimpleTextShadowNode;
      if (textNode != null)
      {
        textNode.UpdateTextBlock((TextBlock)view.Content);
      }
    }
  }

Activity

  1. ghost added
    Needs: Triage 🔍
    on Oct 30, 2020
  2. added
    Needs: Author Feedback
    and removed
    Needs: Triage 🔍
    on Nov 2, 2020
  3. chrisglein commented on Nov 2, 2020

    @chrisglein
    Member

    The documentation for view managers is here. Is your question specifically about patterns of how to move from using shadow nodes to whatever the new pattern is? Hopefully the docs I linked are helpful, if they are not let us know what would be helpful. We're always looking for feedback on the docs and trying to improve them.

  4. vijay-kadam commented on Nov 4, 2020

    @vijay-kadam
    Author

    Yes my question in specifically about how we can move from shadow node with new view managers. As now i am not able to see Hyperlink and textblock with below code snippet using AttributedViewManager as AttributedViewManager(HyperlinkButton)

    `

    public class ReactHyperlinkButtonViewManager : AttributedViewManager
    {
    public override string Name => "RCTHyperlinkButtonView";

    public override FrameworkElement CreateView()
    {
      var view = new HyperlinkButton();
      view.Content = new TextBlock();
      return view;
    }
    [ViewManagerProperty("text")]
    public void SetText(HyperlinkButton view, string text)
    {
      TextBlock txtBlock = (TextBlock)view.Content;
      txtBlock.Text = text;
    }
    

    }

    `

  5. ghost added
    Needs: Attention 👋
    on Nov 4, 2020
  6. ghost removed
    Needs: Author Feedback
    on Nov 4, 2020
  7. chrisglein commented on Nov 5, 2020

    @chrisglein
    Member

    Is that code snippet from your old implementation? After 0.59 AttributedViewManager isn't part of the plan anymore.
    With something like HyperlinkButton that's going to not be a fixed size and very much need to measure text, you're going to run into an issue without this: #6411. In the meantime try assigning a fixed width/height and see if that gets your element to show up.

    If you you turn on the Live Visual Tree in Visual Studio do you see the elements you've created? That may help understand what is and isn't working.

  8. added
    Needs: Author Feedback
    and removed
    Needs: Attention 👋
    on Nov 5, 2020
  9. rectified95 commented on Nov 7, 2020

    @rectified95
    Contributor

    vijay-kadam As Chris says, our docs should be helpful in understanding how to use custom view managers in your native modules.
    If you want a concrete example of what the transition can look like, you can compare DatePickerViewManager.cpp in this repo, with my community module implementation: react-native-datetimepicker/datetimepicker#157

  10. ghost added
    no-recent-activity
    on Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: Native ModulesNeeds: Author Feedbackno-recent-activityquestion

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions