defensive nil checks around CanvasForObject
This commit is contained in:
@@ -124,7 +124,9 @@ func NewVolumeSlider(width float32) *volumeSlider {
|
||||
|
||||
func (v *volumeSlider) Tapped(e *fyne.PointEvent) {
|
||||
v.Slider.Tapped(e)
|
||||
fyne.CurrentApp().Driver().CanvasForObject(v).Unfocus()
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(v); c != nil {
|
||||
c.Unfocus()
|
||||
}
|
||||
}
|
||||
|
||||
func (v *volumeSlider) MinSize() fyne.Size {
|
||||
|
||||
@@ -67,7 +67,9 @@ func (g *FocusList) FocusNeighbor(curItem widget.ListItemID, up bool) {
|
||||
other := g.ItemForID(focusIdx)
|
||||
g.mutex.Unlock()
|
||||
if other != nil {
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g).Focus(other.(fyne.Focusable))
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(g); c != nil {
|
||||
c.Focus(other.(fyne.Focusable))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,8 +122,7 @@ func (l *FocusListRowBase) SetItemID(id widget.ListItemID) {
|
||||
|
||||
func (l *FocusListRowBase) EnsureUnfocused() {
|
||||
if l.Focused {
|
||||
c := fyne.CurrentApp().Driver().CanvasForObject(l)
|
||||
if c != nil {
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(l); c != nil {
|
||||
c.Unfocus()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -286,7 +286,9 @@ func (g *GridView) Resize(size fyne.Size) {
|
||||
var _ fyne.Tappable = (*GridView)(nil)
|
||||
|
||||
func (g *GridView) Tapped(*fyne.PointEvent) {
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g).Unfocus()
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(g); c != nil {
|
||||
c.Unfocus()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GridView) createGridWrap() {
|
||||
@@ -343,7 +345,9 @@ func (g *GridView) createNewItemCard() fyne.CanvasObject {
|
||||
g.grid.ScrollTo(focusIndex)
|
||||
g.stateMutex.RLock()
|
||||
if item, ok := g.itemForIndex[focusIndex]; ok {
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g).Focus(item)
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(g); c != nil {
|
||||
c.Focus(item)
|
||||
}
|
||||
}
|
||||
g.stateMutex.RUnlock()
|
||||
}
|
||||
|
||||
@@ -513,8 +513,10 @@ func (g *GridViewItem) Update(model *GridViewItemModel) {
|
||||
g.secondaryText.Refresh()
|
||||
g.Cover.ResetPlayButton()
|
||||
if g.focused {
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g).Focus(nil)
|
||||
g.FocusLost()
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(g); c != nil {
|
||||
c.Unfocus()
|
||||
g.FocusLost()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -589,7 +591,9 @@ func (g *GridViewItem) TypedRune(rune) {
|
||||
var _ fyne.Tappable = (*GridViewItem)(nil)
|
||||
|
||||
func (g *GridViewItem) Tapped(*fyne.PointEvent) {
|
||||
fyne.CurrentApp().Driver().CanvasForObject(g).Unfocus()
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(g); c != nil {
|
||||
c.Unfocus()
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GridViewItem) CreateRenderer() fyne.WidgetRenderer {
|
||||
|
||||
@@ -50,7 +50,9 @@ func (t *TrackPosSlider) Tapped(e *fyne.PointEvent) {
|
||||
t.Slider.Tapped(e)
|
||||
|
||||
// don't keep focus after being tapped
|
||||
fyne.CurrentApp().Driver().CanvasForObject(t).Focus(nil)
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(t); c != nil {
|
||||
c.Unfocus()
|
||||
}
|
||||
}
|
||||
|
||||
// override to increase the distance moved by keyboard control
|
||||
|
||||
@@ -50,7 +50,9 @@ func (sf *SearchEntry) Init() {
|
||||
func (s *SearchEntry) TypedKey(e *fyne.KeyEvent) {
|
||||
if e.Name == fyne.KeyEscape {
|
||||
s.SetText("")
|
||||
fyne.CurrentApp().Driver().CanvasForObject(s).Unfocus()
|
||||
if c := fyne.CurrentApp().Driver().CanvasForObject(s); c != nil {
|
||||
c.Unfocus()
|
||||
}
|
||||
return
|
||||
}
|
||||
s.Entry.TypedKey(e)
|
||||
|
||||
Reference in New Issue
Block a user