Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spacing problem #160

Open
yashshekhada opened this issue Jul 10, 2018 · 6 comments
Open

spacing problem #160

yashshekhada opened this issue Jul 10, 2018 · 6 comments

Comments

@yashshekhada
Copy link

hello. currently i faced passing problem can you suggest ,which changes is required
screen shot 2018-07-10 at 5 05 46 pm

and my code is

`<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

         xmlns:local1="clr-namespace:HireME.CustomCells"
         x:Class="HireME.ChatDetailspage" >
<ContentPage.Resources>
    <ResourceDictionary>
        <local1:SelectorDataTemplate x:Key="MessageTemplateSelector"/>
    </ResourceDictionary>
</ContentPage.Resources>

<ContentPage.Content>

<StackLayout HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Orientation="Vertical">

   
   
        <StackLayout Orientation="Vertical" VerticalOptions="FillAndExpand"   BackgroundColor="White"  >
        <ListView 
                    HorizontalOptions="FillAndExpand"
                    VerticalOptions="FillAndExpand"
        x:Name="MessagesListView" 
        ItemTemplate="{StaticResource MessageTemplateSelector}" 
        ItemsSource="{Binding ListMessages}" 
        HasUnevenRows="True" SeparatorVisibility="None" IsEnabled="True"  />
        </StackLayout>
  <StackLayout Orientation="Horizontal" x:Name="mystack" BackgroundColor="#f9f9f9">
                <!--<Image Source="dashboard1.png" WidthRequest="40" HeightRequest="40" Margin="2,4,2,4">
                    <Image.GestureRecognizers>
                        <TapGestureRecognizer
                            Command="{Binding SendCommand}" />
                    </Image.GestureRecognizers>
                </Image>-->

                <Button Image="dashboard1.png" x:Name="mngbutton" Clicked="dashboard_click"></Button>
                <Entry 
            HorizontalOptions="FillAndExpand"  
            Placeholder="Message"  
                VerticalOptions="EndAndExpand"
            x:Name="MSG"
            Text="{Binding OutText}" Keyboard="Chat" Margin="2,4,2,4"/>

                <Image Source="sendButton.png" BackgroundColor="#f9f9f9" WidthRequest="30" HeightRequest="30" >
                <Image.GestureRecognizers>
                    <TapGestureRecognizer
                            Command="{Binding SendCommand}" />
                </Image.GestureRecognizers>
            </Image>

        </StackLayout>

    </StackLayout>
        

 

        
   </ContentPage.Content>

`

@plsgard
Copy link

plsgard commented Aug 17, 2018

Hi,

I've just encountered the same problem. If you are in the same case as me, this space corresponds to the height of the tabbar.
I got this situation since I keep Tabbar always visible. During the calculation, the plugin does not consider the height of the tabbar.

private double CalculateShiftByAmount(double pageHeight, nfloat keyboardHeight, double activeViewBottom)
{
     return (pageHeight - activeViewBottom) - keyboardHeight;
}

I'm working on a solution but I haven't finished yet. You can try this by editing the plugin renderer:

private double CalculateShiftByAmount(double pageHeight, nfloat keyboardHeight, double activeViewBottom)
{
     return (pageHeight - activeViewBottom) - keyboardHeight + (TabBarController?.TabBar?.Frame.Height ?? 0);
}

@matteopiccioni
Copy link

I have the same issues, with TabBar
news for a fix?
Thanks

@MaxxDelusional
Copy link

This issue seems like a duplicate of #103

@matheuscschenfeld
Copy link

@plsgard Did you find a solution for this issue? I am facing the same problem

@plsgard
Copy link

plsgard commented Feb 11, 2020

I didn't work on this project since a year, but here it is my render implementation. I took the base render of the plugin and add my own CalculateShiftByAmount

        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);


            var page = Element as ContentPage;

            if (page != null)
            {
                if (page is OverlapContentPage baseContentPage)
                {
                    _upMore = baseContentPage.OverlapUpMore;
                    _toReduce = baseContentPage.OverlapReduce;
                }

                var contentScrollView = page.Content as ScrollView;

                if (contentScrollView != null)
                    return;

                RegisterForKeyboardNotifications();
            }
        }

        public override void ViewWillDisappear(bool animated)
        {
            base.ViewWillDisappear(animated);

            UnregisterForKeyboardNotifications();
        }

        void RegisterForKeyboardNotifications()
        {
            if (_keyboardShowObserver == null)
                _keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, OnKeyboardShow);
            if (_keyboardHideObserver == null)
                _keyboardHideObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillHideNotification, OnKeyboardHide);
        }

        void UnregisterForKeyboardNotifications()
        {
            _isKeyboardShown = false;
            if (_keyboardShowObserver != null)
            {
                NSNotificationCenter.DefaultCenter.RemoveObserver(_keyboardShowObserver);
                _keyboardShowObserver.Dispose();
                _keyboardShowObserver = null;
            }

            if (_keyboardHideObserver != null)
            {
                NSNotificationCenter.DefaultCenter.RemoveObserver(_keyboardHideObserver);
                _keyboardHideObserver.Dispose();
                _keyboardHideObserver = null;
            }
        }

        protected virtual void OnKeyboardShow(NSNotification notification)
        {
            try
            {
                if (!IsViewLoaded || _isKeyboardShown)
                    return;

                _isKeyboardShown = true;
                var activeView = View.FindFirstResponder();

                if (activeView == null)
                    return;

                var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);
                var isOverlapping = activeView.IsKeyboardOverlapping(View, keyboardFrame);

                if (!isOverlapping)
                    return;

                if (isOverlapping)
                {
                    _activeViewBottom = activeView.GetViewRelativeBottom(View);
                    if (_toReduce)
                        ShiftPageUp(keyboardFrame.Height, _activeViewBottom);
                    else
                        MovePageUp(keyboardFrame.Height, _activeViewBottom);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Microsoft.AppCenter.Crashes.Crashes.TrackError(ex);
            }
        }

        private void OnKeyboardHide(NSNotification notification)
        {
            try
            {
                if (!IsViewLoaded)
                    return;

                _isKeyboardShown = false;
                //var keyboardFrame = UIKeyboard.FrameEndFromNotification(notification);

                if (_pageWasShiftedUp)
                {
                    if (_toReduce)
                        ShiftPageDown(/*keyboardFrame.Height, _activeViewBottom*/);
                    else
                        MovePageDown(/*keyboardFrame.Height, _activeViewBottom*/);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                Microsoft.AppCenter.Crashes.Crashes.TrackError(ex);
            }
        }

        private void MovePageUp(nfloat keyboardHeight, double activeViewBottom)
        {
            var pageFrame = Element.Bounds;

            _baseY = pageFrame.Y;

            var newY = pageFrame.Y + CalculateShiftByAmount(pageFrame.Height, keyboardHeight, activeViewBottom);

            Element.LayoutTo(new Rectangle(pageFrame.X, newY,
                pageFrame.Width, pageFrame.Height));

            _pageWasShiftedUp = true;
        }

        private void ShiftPageUp(nfloat keyboardHeight, double activeViewBottom)
        {
            var pageFrame = Element.Bounds;

            _shift = CalculateShiftByAmount(pageFrame.Height, keyboardHeight, activeViewBottom);
            _newHeight = pageFrame.Height + _shift;

            Element.LayoutTo(new Rectangle(pageFrame.X, pageFrame.Y,
                                           pageFrame.Width, _newHeight));

            _pageWasShiftedUp = true;
        }

        private void MovePageDown()
        {
            var pageFrame = Element.Bounds;

            //var newY = _baseY;//pageFrame.Y - CalculateShiftByAmount(pageFrame.Height, keyboardHeight, activeViewBottom);

            Element.LayoutTo(new Rectangle(pageFrame.X, 0,
                pageFrame.Width, pageFrame.Height));

            _pageWasShiftedUp = false;
        }

        private void ShiftPageDown()
        {
            var pageFrame = Element.Bounds;

            Element.LayoutTo(new Rectangle(pageFrame.X, pageFrame.Y,
                                           pageFrame.Width, _newHeight - _shift));

            _pageWasShiftedUp = false;
        }

        private double CalculateShiftByAmount(double pageHeight, nfloat keyboardHeight, double activeViewBottom)
        {
            return (pageHeight - activeViewBottom - _upMore) - keyboardHeight + (TabBarController?.TabBar?.Frame.Height ?? 0);
        }
    }

Hope this will help. Sorry for the delay.

@matheuscschenfeld
Copy link

Thank you so much @plsgard. I will study your code and implement in my solution. I will share the result here with you.
Thanks again for your attention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants