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

BorderLayout does not respect visibility on mobile #2755

Closed
xxxserxxx opened this issue Jan 26, 2022 · 12 comments
Closed

BorderLayout does not respect visibility on mobile #2755

xxxserxxx opened this issue Jan 26, 2022 · 12 comments
Labels
duplicate This issue or pull request already exists

Comments

@xxxserxxx
Copy link

xxxserxxx commented Jan 26, 2022

On Android, BorderLayout is absolute and does not respond to changes in screen size, such as when a keyboard is opened that effectively shrinks the screen. In this case, the keyboard covers the widgets; if the entry widget is at the bottom of the screen, this can make the entry widget hidden.

To Reproduce:

Compile the supplied code for Android; install it, and try to use the text widget at the bottom of the screen.

fyne package -os android -appId com.test.fynetest -icon someRandomIcon.png

Screenshots:

Full app, with list and text entry widget at bottom:

Screenshot_20220126-173649

App with the keyboard open (after clicking on the text widget):

Screenshot_20220126-173700

Example code:

package main

import (
	"fmt"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/container"
	"fyne.io/fyne/v2/layout"
	"fyne.io/fyne/v2/theme"
	"fyne.io/fyne/v2/widget"
)

func main() {
	a := app.NewWithID("net.ser1.forage")

	w := a.NewWindow("Forage")

	items := make([]string, 20)
	for i:=0; i<20; i++ {
		items[i] = fmt.Sprintf("Item #%d", i)
	}

	itemList := widget.NewList(
		func() int {
			return len(items)
		},
		func() fyne.CanvasObject {
			return widget.NewLabel("Template")
		},
		func(it widget.ListItemID, o fyne.CanvasObject) {
			c, _ := o.(*widget.Label)
			c.Text = items[it]
			c.Refresh()
		},
	)
	lambda :=  func(val string) {
		items = append(items, val)
		itemList.Refresh()
	}
	addItem := widget.NewEntry()
	addItem.OnSubmitted = lambda
	addButton := widget.NewButtonWithIcon("", theme.ContentAddIcon(), func(){ lambda(addItem.Text) })
	addRow := container.New(layout.NewBorderLayout(nil, nil, nil, addButton), addItem, addButton)

	c := container.New(layout.NewBorderLayout(nil, addRow, nil, nil), itemList, addRow)
	itemList.Refresh()
	w.SetContent(c)
	w.ShowAndRun()
}

Device (please complete the following information):

  • OS: Android (compiled on Linux)
  • Version: 12 (Samsung's version 4.0)
  • Go version: 1.17.6
  • Fyne version: v2.1.2 h1:avp9CvLAUdvE7fDMtH1tVKyjxEWHWcpow6aI6L7Kvvw=
@xxxserxxx xxxserxxx added the unverified A bug that has been reported but not verified label Jan 26, 2022
@Jacalz
Copy link
Member

Jacalz commented Jan 27, 2022

I'm not sure if this is specific to how borderlayout works. It is probably a general issue with layouts not shrinking when the keyboard pops up.

@xxxserxxx
Copy link
Author

Fair comment; borderlayout is where I noticed it; I didn't try any other layouts.

My work-around is to put entry widgets at the top.

@Bluebugs
Copy link
Contributor

It might be possible that the window doesn't get resized under Android. Their seems to be a list of different policy for what to do in the application manifest. I do not know where to find it in Fyne code base if anyone knows?

@Jacalz
Copy link
Member

Jacalz commented Jan 27, 2022

The Android manifest file template can be found here. It probably should be moved into the template folder sometime.

@Bluebugs
Copy link
Contributor

Bluebugs commented Jan 27, 2022

Thanks @Jacalz.

@xxxserxxx would you mind changing the manifest and add a line in the <activity> tag with following the attribute: android:windowSoftInputMode="adjustResize".

It might look like:

	<activity android:name="org.golang.app.GoNativeActivity"
		android:label="{{.Name}}"
		android:configChanges="orientation|keyboardHidden|uiMode"
		android:windowSoftInputMode="adjustResize"
		android:theme="@android:style/Theme">
		<meta-data android:name="android.app.lib_name" android:value="{{.LibName}}" />
		<intent-filter>
			<action android:name="android.intent.action.MAIN" />
			<category android:name="android.intent.category.LAUNCHER" />
		</intent-filter>
	</activity>

If that fix your problem, I could do a PR for it that would also address @Jacalz good point that it should be a template and bundled.

@Bluebugs
Copy link
Contributor

For later reference, the reason why the window doesn't get resized by default might be for performance reason and it might be better to track the area where the keyboard is instead of forcing a resize. Reference example code: https://falsinsoft.blogspot.com/2017/04/qml-resize-controls-when-android.html . This is of course more work, and I would put that on a follow up issue if the manifest change solve the problem.

@Jacalz
Copy link
Member

Jacalz commented Jan 27, 2022

If that fix your problem, I could do a PR for it that would also address @Jacalz good point that it should be a template and bundled.

Thanks. I think the reason that it initially wasn't moved to the template folder (when I created the template package some time ago) was to keep our gomobile close to upstream. However, a lot has happened with our mobile package since then and I'm not sure if that argument really stands any more. I think the benefits of having it in the template folder are far larger than any issues with not being close to upstream.

@andydotxyz
Copy link
Member

I think this is a duplicate of #566

@andydotxyz andydotxyz added duplicate This issue or pull request already exists and removed unverified A bug that has been reported but not verified labels Jan 27, 2022
@xxxserxxx
Copy link
Author

@andydotxyz I think so too. My search didn't turn that one up, but I may have been focusing on the layout. I'm testing @Bluebugs' suggestion, but after that do you want me to close this one?

@xxxserxxx
Copy link
Author

@Bluebugs: that didn't address the issue, unfortunately. I did check to make sure the right manifest got used by unzipping the APK and using axmldec.

@Bluebugs
Copy link
Contributor

@xxxserxxx that's a disappointing news. I guess we will have to implement in code then. I am focusing on the web platform at the moment, but I have on my todo to do some work on Android. In which case, I think we should close this issue and focus on #566.

@Jacalz
Copy link
Member

Jacalz commented Jan 28, 2022

I agree. Let's close this as a duplicate of that one.

@Jacalz Jacalz closed this as completed Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

4 participants