Skip to content

[Missing] sysytem.CommandEvent missing #2

Description

@diyism

I'm always using sysytem.CommandEvent to control the "Back Button" behavior in android:

func loop(w *app.Window) error
{	th := material.NewTheme(gofont.Collection())
	var ops op.Ops
	var wv  gowebview.WebView
	for
	{	e:=<-w.Events()
		switch e:=e.(type)
		{	case app.ViewEvent:
				if wv==nil
				{	go func()
					{	var err error
						wv,err = gowebview.New(&gowebview.Config{URL:"https://google.com/ncr", WindowConfig:&gowebview.WindowConfig{Title:"Hello World", Window:e.View, VM:app.JavaVM()}})
						if err!=nil {panic(err)}
						defer wv.Destroy()
						wv.Run()
					}()
				}
			case *system.CommandEvent:
				if e.Type==system.CommandBack
				{	log.Println("===================back button hibernate==============", wv)
					e.Cancel = true
					//wv.SetVisibility(gowebview.VisibilityMinimized)
					go wv.Hibernate()
				}

I can see the system.CommandEvent and system.CommandBack in gioui.org/io/system/system.go(v0.0.0-20210817080256-3773daf155b4):

// CommandEvent is a system event. Unlike most other events, CommandEvent is
// delivered as a pointer to allow Cancel to suppress it.
type CommandEvent struct {
	Type CommandType
	// Cancel suppress the default action of the command.
	Cancel bool
}

// Stage of a Window.
type Stage uint8

// CommandType is the type of a CommandEvent.
type CommandType uint8

const (
	// StagePaused is the Stage for inactive Windows.
	// Inactive Windows don't receive FrameEvents.
	StagePaused Stage = iota
	// StateRunning is for active Windows.
	StageRunning
)

const (
	// CommandBack is the command for a back action
	// such as the Android back button.
	CommandBack CommandType = iota
)

But now the system.CommandEvent and system.CommandBack have been removed in gioui.org/io/system/system.go(v0.0.0-20220425071242-aa14056350d6)

So how can I handle the BackButton in android?
Could you restore the system.CommandEvent and system.CommandBack in gioui.org/io/system/system.go?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions