Added PopupShowAnimation and SetPopupShowAnimation methods to Session interface

This commit is contained in:
Alexei Anoshenko 2026-05-17 20:18:20 +03:00
parent 6c84f332aa
commit 6aae7f2272
3 changed files with 126 additions and 8 deletions

View File

@ -3,6 +3,7 @@
* Removed "style-disabled" property and GetDisabledStyle function * Removed "style-disabled" property and GetDisabledStyle function
* Added GoogleFonts field to AppParams * Added GoogleFonts field to AppParams
* Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded * Added functions: GetWhiteSpace, GetWordBreak, ScrollIntoViewIfNeeded
* Added PopupShowAnimation and SetPopupShowAnimation methods to Session interface
# v0.20.0 # v0.20.0

View File

@ -658,6 +658,18 @@ func (popup *popupData) Set(tag PropertyName, value any) bool {
case ShowTransform: case ShowTransform:
return setTransformProperty(popup, tag, value) return setTransformProperty(popup, tag, value)
case ShowOpacity:
return len(setFloatProperty(popup, ShowOpacity, value, 0, 1)) > 0
case ShowDuration:
return len(setFloatProperty(popup, ShowDuration, value, 0, 60)) > 0
case ShowTiming:
if timing, ok := value.(string); ok && isTimingFunctionValid(timing) {
popup.setRaw(ShowTiming, timing)
return true
}
} }
if popup.supported(tag) { if popup.supported(tag) {
@ -775,10 +787,12 @@ func (popup *popupData) propertyChanged(tag PropertyName) {
} }
func (popup *popupData) animationProperty() AnimationProperty { func (popup *popupData) animationProperty() AnimationProperty {
duration, _ := floatProperty(popup, ShowDuration, popup.session, 1) _, _, defaultDuration, defaultTiming := popup.session.PopupShowAnimation()
duration, _ := floatProperty(popup, ShowDuration, popup.session, defaultDuration)
timing, ok := stringProperty(popup, ShowTiming, popup.session) timing, ok := stringProperty(popup, ShowTiming, popup.session)
if !ok { if !ok {
timing = EaseTiming timing = defaultTiming
} }
return NewAnimationProperty(Params{ return NewAnimationProperty(Params{
Duration: duration, Duration: duration,
@ -926,12 +940,31 @@ func (popup *popupData) Show() {
popup.Session().popupManager().showPopup(popup) popup.Session().popupManager().showPopup(popup)
} }
func (popup *popupData) showAnimation() { func (popup *popupData) showTransformAndOpacity() (TransformProperty, float64) {
opacity, _ := floatProperty(popup, ShowOpacity, popup.session, 1) defaultTransform, defaultOpacity, _, _ := popup.session.PopupShowAnimation()
transform := getTransformProperty(popup, ShowTransform)
opacity, _ := floatProperty(popup, ShowOpacity, popup.session, defaultOpacity)
transform := getTransformProperty(popup, ShowTransform)
if transform == nil {
transform = defaultTransform
}
return transform, opacity
}
func (popup *popupData) showAnimation() {
transform, opacity := popup.showTransformAndOpacity()
if opacity != 1 || transform != nil { if opacity != 1 || transform != nil {
htmlID := popup.popupView.htmlID() htmlID := popup.popupView.htmlID()
animation := popup.animationProperty()
if opacity != 1 {
popup.popupView.SetTransition(Opacity, animation)
}
if transform != nil {
popup.popupView.SetTransition(Transform, animation)
}
session := popup.Session() session := popup.Session()
if opacity != 1 { if opacity != 1 {
session.updateCSSProperty(htmlID, string(Opacity), "1") session.updateCSSProperty(htmlID, string(Opacity), "1")
@ -943,9 +976,7 @@ func (popup *popupData) showAnimation() {
} }
func (popup *popupData) dismissAnimation(listener func(PropertyName)) bool { func (popup *popupData) dismissAnimation(listener func(PropertyName)) bool {
opacity, _ := floatProperty(popup, ShowOpacity, popup.session, 1) transform, opacity := popup.showTransformAndOpacity()
transform := getTransformProperty(popup, ShowTransform)
if opacity != 1 || transform != nil { if opacity != 1 || transform != nil {
session := popup.Session() session := popup.Session()
popup.popupView.Set(TransitionEndEvent, listener) popup.popupView.Set(TransitionEndEvent, listener)
@ -1287,6 +1318,38 @@ func NewPopup(view View, param Params) Popup {
popup.session = view.Session() popup.session = view.Session()
popup.contentView = view popup.contentView = view
popup.properties = map[PropertyName]any{} popup.properties = map[PropertyName]any{}
defaultTransform, defaultOpacity, duration, timing := popup.session.PopupShowAnimation()
if value, ok := param[ShowTransform]; ok {
if transform := valueToTransformProperty(value); transform != nil {
defaultTransform = transform
} else {
param[ShowTransform] = defaultTransform
}
} else if defaultTransform != nil {
param[ShowTransform] = defaultTransform
}
if value, ok := param[ShowOpacity]; ok {
if opacity, _ := valueToFloat(value, popup.session, 1); opacity >= 0 && opacity < 1 {
defaultOpacity = opacity
} else {
param[ShowOpacity] = defaultOpacity
}
} else if defaultOpacity != 1 {
param[ShowOpacity] = defaultOpacity
}
if defaultTransform != nil || defaultOpacity != 1 {
if _, ok := param[ShowDuration]; !ok {
param[ShowDuration] = duration
}
if _, ok := param[ShowTiming]; !ok {
param[ShowTiming] = timing
}
}
for tag, value := range param { for tag, value := range param {
popup.Set(tag, value) popup.Set(tag, value)
} }

View File

@ -45,34 +45,47 @@ type SessionContent interface {
type Session interface { type Session interface {
// App return the current application interface // App return the current application interface
App() Application App() Application
// ID return the id of the session // ID return the id of the session
ID() int ID() int
// DarkTheme returns "true" if the dark theme is used // DarkTheme returns "true" if the dark theme is used
DarkTheme() bool DarkTheme() bool
// Mobile returns "true" if current session is displayed on a touch screen device // Mobile returns "true" if current session is displayed on a touch screen device
TouchScreen() bool TouchScreen() bool
// PixelRatio returns the ratio of the resolution in physical pixels to the resolution // PixelRatio returns the ratio of the resolution in physical pixels to the resolution
// in logical pixels for the current display device. // in logical pixels for the current display device.
PixelRatio() float64 PixelRatio() float64
// TextDirection returns the default text direction (LeftToRightDirection (1) or RightToLeftDirection (2)) // TextDirection returns the default text direction (LeftToRightDirection (1) or RightToLeftDirection (2))
TextDirection() int TextDirection() int
// Constant returns the constant with "tag" name or "" if it is not exists // Constant returns the constant with "tag" name or "" if it is not exists
Constant(tag string) (string, bool) Constant(tag string) (string, bool)
// Color returns the color with "tag" name or 0 if it is not exists // Color returns the color with "tag" name or 0 if it is not exists
Color(tag string) (Color, bool) Color(tag string) (Color, bool)
// ImageConstant returns the image constant with "tag" name or "" if it is not exists // ImageConstant returns the image constant with "tag" name or "" if it is not exists
ImageConstant(tag string) (string, bool) ImageConstant(tag string) (string, bool)
// SetCustomTheme set the custom theme // SetCustomTheme set the custom theme
SetCustomTheme(name string) bool SetCustomTheme(name string) bool
// UserAgent returns the "user-agent" text of the client browser // UserAgent returns the "user-agent" text of the client browser
UserAgent() string UserAgent() string
// RemoteAddr returns the client address. // RemoteAddr returns the client address.
RemoteAddr() string RemoteAddr() string
// Language returns the current session language // Language returns the current session language
Language() string Language() string
// SetLanguage set the current session language // SetLanguage set the current session language
SetLanguage(lang string) SetLanguage(lang string)
// GetString returns the text for the current language // GetString returns the text for the current language
GetString(tag string) (string, bool) GetString(tag string) (string, bool)
@ -82,32 +95,48 @@ type Session interface {
// SetTitle sets the text of the browser title/tab // SetTitle sets the text of the browser title/tab
SetTitle(title string) SetTitle(title string)
// SetTitleColor sets the color of the browser navigation bar. Supported only in Safari and Chrome for android // SetTitleColor sets the color of the browser navigation bar. Supported only in Safari and Chrome for android
SetTitleColor(color Color) SetTitleColor(color Color)
// RootView returns the root view of the session // RootView returns the root view of the session
RootView() View RootView() View
// Get returns a value of the view (with id defined by the first argument) property with name defined by the second argument. // Get returns a value of the view (with id defined by the first argument) property with name defined by the second argument.
// The type of return value depends on the property. If the property is not set then nil is returned. // The type of return value depends on the property. If the property is not set then nil is returned.
Get(viewID string, tag PropertyName) any Get(viewID string, tag PropertyName) any
// Set sets the value (third argument) of the property (second argument) of the view with id defined by the first argument. // Set sets the value (third argument) of the property (second argument) of the view with id defined by the first argument.
// Return "true" if the value has been set, in the opposite case "false" are returned and // Return "true" if the value has been set, in the opposite case "false" are returned and
// a description of the error is written to the log // a description of the error is written to the log
Set(viewID string, tag PropertyName, value any) bool Set(viewID string, tag PropertyName, value any) bool
// PopupShowAnimation returns default popup animation parameters.
// Returns the default value for the properties: "show-transform", "show-opacity", "show-duration" and "show-timing".
PopupShowAnimation() (transform TransformProperty, opacity, duration float64, timing string)
// SetPopupShowAnimation sets default popup animation parameters.
// Sets the default value for the properties: "show-transform", "show-opacity", "show-duration" and "show-timing".
SetPopupShowAnimation(transform TransformProperty, opacity, duration float64, timing string)
// DownloadFile downloads (saves) on the client side the file located at the specified path on the server. // DownloadFile downloads (saves) on the client side the file located at the specified path on the server.
DownloadFile(path string) DownloadFile(path string)
//DownloadFileData downloads (saves) on the client side a file with a specified name and specified content. //DownloadFileData downloads (saves) on the client side a file with a specified name and specified content.
DownloadFileData(filename string, data []byte) DownloadFileData(filename string, data []byte)
// OpenURL opens the url in the new browser tab // OpenURL opens the url in the new browser tab
OpenURL(url string) OpenURL(url string)
// ClientItem reads value by key from the client-side storage // ClientItem reads value by key from the client-side storage
ClientItem(key string) (string, bool) ClientItem(key string) (string, bool)
// SetClientItem stores a key-value pair in the client-side storage // SetClientItem stores a key-value pair in the client-side storage
SetClientItem(key, value string) SetClientItem(key, value string)
// RemoveClientItem removes a key-value pair in the client-side storage // RemoveClientItem removes a key-value pair in the client-side storage
RemoveClientItem(key string) RemoveClientItem(key string)
// RemoveAllClientItems removes all key-value pair from the client-side storage // RemoveAllClientItems removes all key-value pair from the client-side storage
RemoveAllClientItems() RemoveAllClientItems()
@ -120,6 +149,7 @@ type Session interface {
// The second argument specifies a function that will be called on each timer event. // The second argument specifies a function that will be called on each timer event.
// The result is the id of the timer, which is used to stop the timer // The result is the id of the timer, which is used to stop the timer
StartTimer(ms int, timerFunc func(Session)) int StartTimer(ms int, timerFunc func(Session)) int
// StopTimer the timer with the given id // StopTimer the timer with the given id
StopTimer(timerID int) StopTimer(timerID int)
@ -216,6 +246,10 @@ type sessionData struct {
timers map[int]func(Session) timers map[int]func(Session)
nextTimerID int nextTimerID int
pauseTime int64 pauseTime int64
popupTransform TransformProperty
popupOpacity float64
popupDuration float64
popupTiming string
} }
func newSession(app Application, id int, customTheme string, params DataObject) Session { func newSession(app Application, id int, customTheme string, params DataObject) Session {
@ -236,6 +270,9 @@ func newSession(app Application, id int, customTheme string, params DataObject)
session.hotkeys = map[string]func(Session){} session.hotkeys = map[string]func(Session){}
session.timers = map[int]func(Session){} session.timers = map[int]func(Session){}
session.nextTimerID = 1 session.nextTimerID = 1
session.popupOpacity = 1
session.popupDuration = 1
session.popupTiming = EaseTiming
if customTheme != "" { if customTheme != "" {
if theme, ok := CreateThemeFromText(customTheme); ok { if theme, ok := CreateThemeFromText(customTheme); ok {
@ -924,3 +961,20 @@ func (session *sessionData) StopTimer(timerID int) {
delete(session.timers, timerID) delete(session.timers, timerID)
} }
} }
func (session *sessionData) SetPopupShowAnimation(transform TransformProperty, opacity, duration float64, timing string) {
session.popupTransform = transform
if opacity >= 0 && opacity <= 1 {
session.popupOpacity = opacity
}
if duration > 0 {
session.popupDuration = duration
}
if isTimingFunctionValid(timing) {
session.popupTiming = timing
}
}
func (session *sessionData) PopupShowAnimation() (transform TransformProperty, opacity, duration float64, timing string) {
return session.popupTransform, session.popupOpacity, session.popupDuration, session.popupTiming
}