Git Product home page Git Product logo

xbottomsheet's Introduction

XBottomSheet

Build Status

XBottomSheet.Touch XBottomSheet.Droid .Touch.Sample .Droid.Sample
Build status Build status Build status Build status

Preview

Blogs

https://butonium.com/custom-bottomsheet-xamarin/

Setup

On client projects install the nuget XBottomSheet (NuGet) and then follow the steps based on platform:

iOS

Standard

  1. Create a new ViewController of type BottomSheetViewController within the ViewController that you want to add it to:
public override void ViewDidLoad()
{
    base.ViewDidLoad();
    var bottomSheetViewController = new BottomSheetViewController(100, 300, 500, true, BottomSheetState.Bottom);
}

For more details on options for the constructors or their parameters, please check the implementation.

  1. Add the newly created ViewController as a child to the current one:
    AddChildViewController(bottomSheetViewController);
    View.AddSubview(bottomSheetViewController.View);
    bottomSheetViewController.DidMoveToParentViewController(this);
  1. Define the Frame for the View of the BottomSheet control:
    bottomSheetViewController.View.Frame = new CGRect(0, View.Frame.GetMaxY(), View.Frame.Width, View.Frame.Height);
  1. Add your custom view within as until now it would be only a blue view that can be dragged around:
    customView = CustomView.Create();
    customView.Frame = View.Frame;
    bottomSheetViewController.SetCustomView(customView);

MvvmCross

After following the steps from previous way, continue with following:

  1. As you can add any control within that custom view, in order to make it available for binding, you have to create a public geter/setter for it, similar to this:
    public UILabel CustomValue
    {
        get
        {
            return lbCustomValue;
        }
        set
        {
            lbCustomValue = value;
        }
    }
  1. Within the MainViewController (or parent view controller) create a binding set between the controls that you have in the custom view and the view model associated with the parent view controller:
    var set = this.CreateBindingSet<MainViewController, MainViewModel>();
    set.Bind(customView.CustomValue).For(t => t.Text).To(vm => vm.CustomValue);
    set.Apply();

Check the Touch.MSample for actual sample on how a value is passed in between.

Android

Standard

  1. You can use this view by adding it within your layout:
   <XBottomSheet.Droid.Views.XBottomSheetView
	android:id="@+id/BottomSheet"
	app:anchorOffset="320dp"
	app:peekHeight="192dp"
	app:defaultState="collapsed"
	android:layout_width="match_parent"
	android:layout_height="match_parent">
   </XBottomSheet.Droid.Views.XBottomSheetView>
  1. In order to use a custom view you will need to inflate a desired Android layout file (ex. CustomView.axml) and assign it to the ContentView property of XBottomSheetView:
    var bottomSheetView = FindViewById<XBottomSheetView>(Resource.Id.BottomSheet);
    var customView = LayoutInflater.Inflate(Resource.Layout.CustomView, null);
    
    bottomSheetView.ContentView = customView;
    bottomSheetView.BackgroundColor = Color.Transparent;

MvvmCross

After following previous steps, in order to bind the ViewModel with your CustomView you'll need to replace LayoutInflater.Inflate with BindingInflate

   var customView = this.BindingInflate(Resource.Layout.CustomView, null);

Android

Known issues/difficulties

  • If you add this controll with GMSMapView or other similar feature that has its own gesture management it is possible to prevent XBottomSheet to trigger the PanGesture method, even if it registers it. For GMSMapView, the fix is to have "mapView.Settings.ConsumesGesturesInView = false;", where mapView is your GMSMapView object.

Conclusion

If you have a question or a suggestion, please add an issue and we'll discuss over it. We're open to respond, add new features, fine tune our solutions or, last, but most important, to fix bugs/problems that you encounter.

As you've got this far and our code might helped you, support us to build more content like this through:

Buy Me A Coffee

xbottomsheet's People

Contributors

alexstefan avatar butonium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

xbottomsheet's Issues

XBottomSheet sits over all UI always

I'm trying to position a XBottomSheet directly above a TabBar on Xamarin.iOS. Unfortunately, no matter what I attempt, it always sits over the TabBar, therefore intercepting all taps meant for the Tab Bar.

What I'm trying to achieve is similar to apps, such as Apple Music, where you have an expandable playback bar that's on top of the app's bottom tab bar.

Bottom sheet can be lifted above the bottom of the screen

Hello!
I've added the Bottom Sheet to my project and there is an issue I'm not sure how to handle - bottom sheet can be... "picked above" the bottom of the screen.
Initial state:
Screenshot 2019-12-24 at 18 23 33
and it can be drug above until screen allows like this
Screenshot 2019-12-24 at 18 23 13
Is there a way to "glue" it to the bottom of the screen so it's impossible to detach it from the screen bottom?

Thanks

XBottomSheet hidden by default

@AlexStefan I'd like to keep the default state of the bottom sheet as hidden. I'd like the bottom sheet to show when a button is clicked. I'm trying to implement this in Xamarin.Android

Could you please help me out with this? I've gone through a few samples and the documentation but couldn't get this particular case to work.

Unable to use this, get the following exceptions. Please help

NotSupportedException: Could not activate JNI Handle 0x7fd2440ce0 (key_handle 0x827b90c) of Java type 'ouefdb344fddfgf/XBottomSheetView' as managed type 'packagename.XBottomSheetView'.

Inner Exception >>
TypeLoadException: Parent class vtable failed to initialize, due to: VTable setup of type AndroidX.CoordinatorLayout.Widget.CoordinatorLayout failed assembly:Xamarin.AndroidX.CoordinatorLayout.dll type:CoordinatorLayout member:(null)

BottomSheet is not showing content

@AlexStefan I passed some content in bottomsheet and that content has a grid. In this grid i used HorizontalOptions="EndAndExpand" for a label but that label is not visible in UI
because it has that "EndAndExpand" options and when i used option as "StartAndExpand" then it is visible clearly. It means we can not use options as "CenterAndExpand" and "EndAndExpand" in bottomsheet content. what is the solution for that?

No resource identifier found for attribute

Hello,

It looks like nuget doesn't actually install attr.xml which give me "No resource identifier found for attribute " compile error for

app:anchorOffset="320dp"
app:peekHeight="192dp"
app:defaultState="collapsed"

Adding it manually in my project resolves that error but then it gives me a weird behavior of the control taking half the screen while collapsed and not just the peekheight

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.