GoFlow provides a comprehensive page transition library inspired by Flutter's page route animations. This guide covers everything you need to know about creating smooth, beautiful transitions between pages in your application.
- Overview
- Quick Start
- Transition Types
- Basic Usage
- Advanced Usage
- Custom Transitions
- Animation Curves
- Best Practices
- API Reference
Page transitions are animations that play when navigating between different pages in your application. They provide visual continuity and help users understand the navigation flow.
- 16+ built-in transitions - From simple fades to complex parallax effects
- Platform-specific styles - iOS (Cupertino) and Material Design transitions
- Fully customizable - Control duration, curves, and create custom transitions
- Seamless integration - Works with GoFlow's navigation system
- Performant - Built on GoFlow's efficient animation framework
import (
"github.com/base-go/GoFlow/pkg/navigation"
goflow "github.com/base-go/GoFlow/pkg/core/framework"
)
// Navigate with a fade transition
navigation.Get.To(NewDetailsPage(), navigation.TransitionFade)// iOS-style transition
navigation.Get.To(NewPage(), navigation.TransitionCupertino)
// Material Design transition
navigation.Get.To(NewPage(), navigation.TransitionMaterial)navigation.TransitionFadeSmoothly fades between pages. Great for subtle transitions.
Use cases: Settings pages, overlays, non-directional navigation
navigation.TransitionSlideRight // or TransitionCupertinoSlides new page in from the right, old page slides out to the left.
Use cases: iOS apps, forward navigation, drill-down patterns
navigation.TransitionSlideLeftSlides new page in from the left.
Use cases: Back navigation, bidirectional navigation
navigation.TransitionSlideUp // or TransitionMaterialSlides new page in from the bottom.
Use cases: Android apps, modal-like pages, bottom sheets to full page
navigation.TransitionSlideDownSlides new page in from the top.
Use cases: Notifications to detail, special emphasis
navigation.TransitionZoomCombines scale and fade for a zoom effect.
Use cases: Image galleries, expanding content, focus transitions
navigation.TransitionNoneInstant transition with no animation.
Use cases: Tab switching, instant updates, accessibility settings
When using the PageTransition widget directly, you have access to additional transition types:
// Combined transitions
navigation.PageTransitionTypeRightToLeftWithFade
navigation.PageTransitionTypeLeftToRightWithFade
// Joined transitions (old page slides out while new slides in)
navigation.PageTransitionTypeRightToLeftJoined
navigation.PageTransitionTypeLeftToRightJoined
// Special effects
navigation.PageTransitionTypeRippleEffect
navigation.PageTransitionTypeSlideParallax
navigation.PageTransitionTypeRotate
navigation.PageTransitionTypeScale// Using Get.To
navigation.Get.To(NewMyPage(), navigation.TransitionSlideRight)
// Using Get.ToNamed
navigation.Get.ToNamed("/settings", navigation.TransitionFade)
// Using Get.Off (replace current page)
navigation.Get.Off(NewHomePage(), navigation.TransitionSlideLeft)
// Using Get.OffAll (clear stack)
navigation.Get.OffAll(NewLoginPage(), navigation.TransitionFade)routes := map[string]navigation.RouteBuilder{
"/home": func() goflow.Widget { return NewHomePage() },
"/details": func() goflow.Widget { return NewDetailsPage() },
}
// Routes can specify default transitions when building the route
route := navigation.NewPageRoute(NewMyPage(), navigation.TransitionFade)The PageTransition widget provides more control over transitions:
import "time"
transition := navigation.NewPageTransition(
navigation.PageTransitionTypeZoom,
myPage,
).WithDuration(500 * time.Millisecond).
WithCurve(animation.EaseInOut)// Set custom duration
transition.WithDuration(400 * time.Millisecond)
// Set animation curve
transition.WithCurve(animation.BounceOut)
// Set alignment for scale/zoom transitions
transition.WithAlignment(goflow.Alignment{X: 0, Y: -1}) // Top center
// Set custom builder
transition.WithMatchingBuilder(myCustomBuilder)For maximum control, create a custom PageTransitionsBuilder:
func MyCustomTransition(
context goflow.BuildContext,
animation *animation.AnimationController,
secondaryAnimation *animation.AnimationController,
child goflow.Widget,
) goflow.Widget {
curvedAnimation := animation.NewCurvedAnimation(animation, animation.EaseInOut)
// Create custom animation
return widgets.NewFadeTransition(curvedAnimation, child)
}Create a slide transition in any direction:
customSlide := navigation.CreateDirectionalSlideTransition(
navigation.TransitionDirectionUp,
600.0, // distance in pixels
)
// Use it with CustomPageTransition
custom := navigation.NewCustomPageTransition(
myPage,
customSlide,
300 * time.Millisecond,
animation.EaseOut,
)scaleRotate := navigation.CreateScaleRotateTransition(
0.5, // initial scale (0.5 = 50%)
0.25, // rotation in turns (0.25 = 90 degrees)
)Implement your own PageTransitionsBuilder:
func MyComplexTransition(
context goflow.BuildContext,
anim *animation.AnimationController,
secondaryAnim *animation.AnimationController,
child goflow.Widget,
) goflow.Widget {
progress := anim.Value()
// Example: Slide + Fade + Scale
offset := (1.0 - progress) * 400
opacity := progress
scale := 0.8 + (progress * 0.2)
scaled := &widgets.Transform{
Transform: &widgets.ScaleTransform{
ScaleX: scale,
ScaleY: scale,
},
Child: child,
}
translated := &widgets.Transform{
Transform: &widgets.TranslationTransform{
X: offset,
Y: 0,
},
Child: scaled,
}
return &widgets.Opacity{
Opacity: opacity,
Child: translated,
}
}Control the easing of your transitions:
import "github.com/base-go/GoFlow/pkg/core/animation"
// Available curves:
animation.Linear // No easing
animation.EaseIn // Slow start
animation.EaseOut // Slow end
animation.EaseInOut // Slow start and end
animation.BounceIn // Bounce at start
animation.BounceOut // Bounce at end
animation.ElasticIn // Elastic at start
animation.ElasticOut // Elastic at endtransition := navigation.NewPageTransition(
navigation.PageTransitionTypeFade,
myPage,
).WithCurve(animation.BounceOut)// For iOS
navigation.Get.To(page, navigation.TransitionCupertino)
// For Android
navigation.Get.To(page, navigation.TransitionMaterial)// Good: 200-400ms for most transitions
transition.WithDuration(300 * time.Millisecond)
// Avoid: Too fast (jarring) or too slow (sluggish)
transition.WithDuration(50 * time.Millisecond) // Too fast
transition.WithDuration(1000 * time.Millisecond) // Too slow// Forward navigation: slide from right
navigation.Get.To(nextPage, navigation.TransitionSlideRight)
// Back navigation: use Back() which reverses the transition
navigation.Get.Back()// Modal or bottom sheet style
navigation.Get.To(modalPage, navigation.TransitionSlideUp)
// Expanding detail view
navigation.Get.To(detailPage, navigation.TransitionZoom)
// Settings or preferences
navigation.Get.To(settingsPage, navigation.TransitionFade)// For simple transitions, use built-in types
navigation.TransitionFade // More performant
// For complex transitions, optimize carefully
// Avoid multiple nested transforms and animations// Provide option to reduce or disable transitions
if userPrefersReducedMotion {
navigation.Get.To(page, navigation.TransitionNone)
} else {
navigation.Get.To(page, navigation.TransitionFade)
}const (
TransitionFade
TransitionSlideRight
TransitionSlideLeft
TransitionSlideUp
TransitionSlideDown
TransitionZoom
TransitionNone
TransitionCupertino // Alias for SlideRight
TransitionMaterial // Alias for SlideUp
)type PageTransition struct {
Type PageTransitionType
Child goflow.Widget
Duration time.Duration
ReverseDuration time.Duration
Curve animation.Curve
MatchingBuilder PageTransitionsBuilder
Alignment goflow.Alignment
IsIOS bool
}
// Constructor
func NewPageTransition(transitionType PageTransitionType, child goflow.Widget) *PageTransition
// Fluent API
func (p *PageTransition) WithDuration(duration time.Duration) *PageTransition
func (p *PageTransition) WithCurve(curve animation.Curve) *PageTransition
func (p *PageTransition) WithAlignment(alignment goflow.Alignment) *PageTransition
func (p *PageTransition) WithMatchingBuilder(builder PageTransitionsBuilder) *PageTransitiontype PageTransitionsBuilder func(
context goflow.BuildContext,
animation *animation.AnimationController,
secondaryAnimation *animation.AnimationController,
child goflow.Widget,
) goflow.Widgetfunc FadeTransitionBuilder(...) goflow.Widget
func RightToLeftTransitionBuilder(...) goflow.Widget
func LeftToRightTransitionBuilder(...) goflow.Widget
func TopToBottomTransitionBuilder(...) goflow.Widget
func BottomToTopTransitionBuilder(...) goflow.Widget
func ScaleTransitionBuilder(...) goflow.Widget
func RotateTransitionBuilder(...) goflow.Widget
func ZoomTransitionBuilder(...) goflow.Widget
func RippleEffectTransitionBuilder(...) goflow.Widget
func SlideParallaxTransitionBuilder(...) goflow.Widget// Create directional slide
func CreateDirectionalSlideTransition(
direction TransitionDirection,
distance float64,
) PageTransitionsBuilder
// Create scale + rotate
func CreateScaleRotateTransition(
initialScale float64,
rotationTurns float64,
) PageTransitionsBuilder
// Map transition types
func MapPageTransitionTypeToTransition(transitionType PageTransitionType) Transitiontype TransitionBuilder func(child goflow.Widget, animation float64) goflow.Widget
// Get builder for transition type
func GetTransitionBuilder(transition Transition) TransitionBuilderSee the complete example in examples/page-transitions-demo/ for a full demonstration of all transition types.
GoFlow's page transitions are designed to be familiar to Flutter developers:
| Flutter | GoFlow |
|---|---|
MaterialPageRoute |
navigation.TransitionMaterial |
CupertinoPageRoute |
navigation.TransitionCupertino |
PageRouteBuilder |
PageTransition widget |
transitionDuration |
Duration field |
transitionsBuilder |
PageTransitionsBuilder |
FadeTransition |
TransitionFade |
SlideTransition |
TransitionSlide* |
ScaleTransition |
TransitionZoom |
Q: Can I have different transitions for push and pop? A: Currently, the reverse transition mirrors the forward transition. Full support for custom reverse transitions is planned.
Q: How do I disable transitions globally?
A: You can create a configuration option that always uses TransitionNone.
Q: Can I animate multiple properties at once?
A: Yes! Create a custom PageTransitionsBuilder that combines multiple transforms and opacity.
Q: What's the difference between PageTransition and Transition?
A: Transition is a simple enum for common transitions. PageTransition is a widget that provides full control over the transition.
Q: How do I make transitions feel more natural?
A: Use appropriate curves! EaseInOut works well for most transitions. Experiment with EaseOut for more natural deceleration.
Want to add a new transition type or improve existing ones? Contributions are welcome! Check out the contributing guide.
GoFlow is licensed under the MIT License. See LICENSE file for details.