Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Looking to implement Tweet button with Xamarin.Forms

$
0
0

I have rewrote my random tips app from the ground up using Xamarin.Forms as someone recommended I do. I want users to be able to hit the Share button and bring up the built in Twitter compose box on iOS. Here's my Xamarin.Forms code below with the composeTweet() function call. Can someone please help me get this implemented in my code?

    namespace Tips
    {
        public class App : Application
        {
            static readonly StackLayout mainStackLayout = new StackLayout {
                BackgroundColor = Color.White,
                Spacing = 0,
            };

            public App ()
            {

                AddTopElement ();


                var shareBtn = new Button {
                    Text = "SHARE",
                    BackgroundColor = Color.FromRgb (0, 144, 219),
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    BorderRadius = 0,
                    HeightRequest = 25,
                    FontFamily = "Helvetica Neue",
                    FontAttributes = FontAttributes.Bold,
                    FontSize = 25,
                    TextColor = Color.White,
                };

                var rateBtn = new Button {
                    Text = "RATE",
                    BackgroundColor = Color.FromRgb (164, 33, 255),
                    HorizontalOptions = LayoutOptions.FillAndExpand,
                    VerticalOptions = LayoutOptions.FillAndExpand,
                    BorderRadius = 0,
                    HeightRequest = 25,
                    FontFamily = "Helvetica Neue",
                    FontAttributes = FontAttributes.Bold,
                    FontSize = 25,
                    TextColor = Color.White,
                };

                mainStackLayout.Children.Add (new StackLayout {
                    HeightRequest = 25,
                    Orientation = StackOrientation.Horizontal,
                    Children = 
                    {
                        shareBtn,
                        rateBtn
                    },
                    Spacing = 0,
                });

                MainPage = new ContentPage {
                    Content = mainStackLayout,
                };

                shareBtn.Clicked += delegate {
                    // ComposeTweet(txtView, this, "test");
                };


            }


            public static void ComposeTweet(UITextView display, UIViewController vc, string tip)
            {
                var tvc = new Twitter.TWTweetComposeViewController ();
                tvc.SetInitialText (tip.ToString ());
                tvc.SetCompletionHandler((Twitter.TWTweetComposeViewControllerResult r)=>{
                    vc.DismissModalViewController(true);
                    if (r == Twitter.TWTweetComposeViewControllerResult.Cancelled)
                    {
                        display.Text = "Cancelled~";
                    }
                    else
                    {
                        display.Text = "Sent!";
                    }
                });
                vc.PresentModalViewController(tvc, true);
            }

            public string getTips()
            {
                // my web service calls
            }


        }
    }

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>