Skip to content

Instantly share code, notes, and snippets.

View rdelrosario's full-sized avatar

Rendy Del Rosario rdelrosario

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace CustomNavigationBarSample
{
public class CustomNavigationPage : NavigationPage
@rdelrosario
rdelrosario / ToolbarAdded.cs
Created December 1, 2017 16:32
Android Toolbar
public override void OnViewAdded(Android.Views.View child)
{
base.OnViewAdded(child);
if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
{
var lastPage = Element?.Navigation?.NavigationStack?.Last();
_toolbar = (Android.Support.V7.Widget.Toolbar)child;
_originalToolbarBackground = _toolbar.Background;
@rdelrosario
rdelrosario / SetupPageTransition.cs
Created December 5, 2017 19:54
Android SetupPageTransition
protected override void SetupPageTransition(Android.Support.V4.App.FragmentTransaction transaction, bool isPush)
{
Page lastPage = null;
if (isPush)
{
if (Element?.Navigation?.NavigationStack?.Count() >= 2)
{
var previousPage = Element?.Navigation?.NavigationStack[Element.Navigation.NavigationStack.Count() - 2];
previousPage.PropertyChanged -= LastPage_PropertyChanged;
@rdelrosario
rdelrosario / OnToolbarChildViewAdded.cs
Created December 5, 2017 20:01
Andriod Tool child view added
void OnToolbarChildViewAdded(object sender, ChildViewAddedEventArgs e)
{
var view = e.Child.GetType();
if (e.Child.GetType() == typeof(Android.Widget.TextView))
{
var textView = (Android.Widget.TextView)e.Child;
textView.Visibility = ViewStates.Gone;
_originalDrawable = textView.Background;
@rdelrosario
rdelrosario / TextFormatted.cs
Created December 5, 2017 20:09
Android - Formatted String
void UpdateFormattedTitleText(Android.Widget.TextView titleTextView, FormattedString formattedString, string defaulTitle)
{
if (formattedString != null && formattedString.Spans.Count > 0)
{
titleTextView.TextFormatted = formattedString.ToAttributed(Font.Default, Xamarin.Forms.Color.Default, titleTextView);
}
else
{
//Update if not formatted text then update with normal title text
UpdateTitleText(titleTextView, defaulTitle);
@rdelrosario
rdelrosario / CustomViewDidLoad.cs
Created December 5, 2017 20:58
ioS renderer custom page
public override void ViewDidLoad()
{
base.ViewDidLoad();
containerView = new UIView()
{
AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth
};
titleView = new UIView()
{
@rdelrosario
rdelrosario / BarSetup.cs
Created December 5, 2017 21:14
iOS Bar Setup
public override void ViewWillAppear(bool animated)
{
base.ViewWillAppear(animated);
SetupNavBar(NavigationController.NavigationBar.Bounds.Size);
SetTitlePosition(CustomNavigationPage.GetTitlePosition(Element), CustomNavigationPage.GetTitlePadding(Element), CustomNavigationPage.GetTitleMargin(Element), new CGRect(0, 0, Math.Max(subtitleLabel.IntrinsicContentSize.Width, titleLabel.IntrinsicContentSize.Width), (titleLabel.IntrinsicContentSize.Height + subtitleLabel.IntrinsicContentSize.Height + (subtitleLabel.IntrinsicContentSize.Height > 0.0f ? 3.0f : 0.0f))));
System.Diagnostics.Debug.WriteLine("Preparing");
}
@rdelrosario
rdelrosario / SetupNavBar.cs
Created December 6, 2017 01:09
iOS Setup NavBar
void SetupNavBar(CGSize size)
{
if (NavigationController != null && titleView != null)
{
var page = Element as Page;
containerView.Frame = new CGRect(0, 0, size.Width, size.Height);
titleView.Layer.BorderWidth = CustomNavigationPage.GetTitleBorderWidth(Element);
titleView.Layer.CornerRadius = CustomNavigationPage.GetTitleBorderCornerRadius(Element);
@rdelrosario
rdelrosario / CreateGradientBackground.cs
Created December 6, 2017 01:13
iOS Create Gradient Background
UIImage CreateGradientBackground(Color startColor, Color endColor, CustomNavigationPage.GradientDirection direction)
{
var gradientLayer = new CAGradientLayer();
gradientLayer.Bounds = NavigationController.NavigationBar.Bounds;
gradientLayer.Colors = new CGColor[] { startColor.ToCGColor(), endColor.ToCGColor() };
switch(direction)
{
case CustomNavigationPage.GradientDirection.LeftToRight:
gradientLayer.StartPoint = new CGPoint(0.0, 0.5);
using System;
using System.Collections.Generic;
using System.Linq;
using SegmentedControlSample.Controls;
using Xamarin.Forms;
namespace SegmentedControlSample
{
public class SegmentedBarControl: ScrollViewWithNotBar
{