@@ -887,7 +887,6 @@ def hidden(self):
887887 self .add_flag (lv .obj .FLAG .HIDDEN )
888888
889889 class AppDrawer (lv .obj ):
890- PAGE_SIZE = 2
891890 PAGE_SLIDE_TIME = 300 # Animation time with ease_out for smooth feel
892891
893892 def __init__ (self , parent ):
@@ -902,6 +901,10 @@ def __init__(self, parent):
902901
903902 # Remove style and lazy loading related code to fix system freeze
904903
904+ # Calculate PAGE_SIZE dynamically
905+ item_count = 7 if utils .BITCOIN_ONLY else 8
906+ self .PAGE_SIZE = (item_count + 3 ) // 4
907+
905908 self .init_ui ()
906909 self .init_items () # Restore original immediate creation of all items
907910 self ._configure_image_cache ()
@@ -1300,6 +1303,58 @@ def hide_to_mainscreen_fallback(self):
13001303 if hasattr (self .parent , "restore_main_content" ):
13011304 self .parent .restore_main_content ()
13021305
1306+ def bounce_page (self , direction ):
1307+ if self .page_animating :
1308+ return
1309+
1310+ self .page_animating = True
1311+ current_wrap = self .page_wraps [self .current_page ]
1312+
1313+ # If swiping LEFT (trying to go next), we move left (negative x) then back
1314+ # If swiping RIGHT (trying to go prev), we move right (positive x) then back
1315+ bounce_dist = 40
1316+ offset = - bounce_dist if direction == lv .DIR .LEFT else bounce_dist
1317+
1318+ original_x = self ._page_wrap_origin_x
1319+ target_x = original_x + offset
1320+
1321+ anim_time = 150
1322+
1323+ def animate_x (target_obj , start_x , end_x , ready_cb = None ):
1324+ anim = lv .anim_t ()
1325+ anim .init ()
1326+ anim .set_var (target_obj )
1327+ anim .set_values (start_x , end_x )
1328+ anim .set_time (anim_time )
1329+ anim .set_path_cb (lv .anim_t .path_ease_out )
1330+
1331+ def exec_cb (_anim , val , * , target = target_obj ):
1332+ target .set_x (int (val ))
1333+
1334+ anim .set_custom_exec_cb (exec_cb )
1335+ if ready_cb :
1336+ anim .set_ready_cb (ready_cb )
1337+ anim .set_repeat_count (1 )
1338+ return anim
1339+
1340+ def on_bounce_back_ready (_anim ):
1341+ self .page_animating = False
1342+ self ._page_anim_refs = []
1343+ self ._page_anim_handles = []
1344+
1345+ def on_bounce_out_ready (_anim ):
1346+ anim_back = animate_x (
1347+ current_wrap , target_x , original_x , on_bounce_back_ready
1348+ )
1349+ self ._page_anim_refs = [anim_back ]
1350+ self ._page_anim_handles = [lv .anim_t .start (anim_back )]
1351+
1352+ anim_out = animate_x (
1353+ current_wrap , original_x , target_x , on_bounce_out_ready
1354+ )
1355+ self ._page_anim_refs = [anim_out ]
1356+ self ._page_anim_handles = [lv .anim_t .start (anim_out )]
1357+
13031358 def handle_page_gesture (self , _dir ):
13041359 if _dir not in [lv .DIR .RIGHT , lv .DIR .LEFT ]:
13051360 return
@@ -1314,9 +1369,13 @@ def handle_page_gesture(self, _dir):
13141369 return
13151370
13161371 if _dir == lv .DIR .LEFT :
1317- target_page = ( self .current_page + 1 ) % self . PAGE_SIZE
1372+ target_page = self .current_page + 1
13181373 else :
1319- target_page = (self .current_page - 1 + self .PAGE_SIZE ) % self .PAGE_SIZE
1374+ target_page = self .current_page - 1
1375+
1376+ if target_page < 0 or target_page >= self .PAGE_SIZE :
1377+ self .bounce_page (_dir )
1378+ return
13201379
13211380 if target_page == self .current_page :
13221381 return
@@ -1374,7 +1433,7 @@ def animate_page_transition(self, target_index: int, direction: int):
13741433 return
13751434
13761435 # Clean up memory before starting animation to prevent GC during animation
1377- gc .collect ()
1436+ # gc.collect() # Removed to improve start smoothness
13781437
13791438 self .page_animating = True
13801439 self ._page_anim_target = target_index
@@ -1490,8 +1549,10 @@ def _on_page_anim_ready(
14901549 self ._page_anim_handles = []
14911550
14921551 # Clean up immediately if forced, otherwise let normal GC handle it
1493- if force :
1494- gc .collect ()
1552+ # if force:
1553+ # gc.collect()
1554+ # Always collect at the end of animation to keep memory clean for next time
1555+ gc .collect ()
14951556
14961557 def force_cleanup (self ):
14971558 self .finish_page_animation (force = True )
0 commit comments