Xamarin.Forms.Plugins icon indicating copy to clipboard operation
Xamarin.Forms.Plugins copied to clipboard

spacing problem

Open yashshekhada opened this issue 6 years ago • 6 comments

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>

</ContentPage>`

yashshekhada avatar Jul 10 '18 11:07 yashshekhada

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);
}

plsgard avatar Aug 17 '18 14:08 plsgard

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

matteopiccioni avatar Oct 04 '18 14:10 matteopiccioni

This issue seems like a duplicate of #103

MaxxDelusional avatar Nov 08 '18 15:11 MaxxDelusional

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

matheuscschenfeld avatar Jan 28 '20 03:01 matheuscschenfeld

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.

plsgard avatar Feb 11 '20 10:02 plsgard

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

matheuscschenfeld avatar Feb 11 '20 15:02 matheuscschenfeld