Fix: mobileview: cant switch tab between code and preview tab #3346
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #3228
Problem:
Currently, the p5.js web editor on mobile devices disables switching between the "Code" and "Preview" tabs while a project is running. This significantly hinders the mobile development experience, making it difficult to debug, iterate, and learn, as users cannot simultaneously view their code and its output. While this functionality exists on desktop, its absence on mobile creates an inconsistent and less effective user experience. This issue is particularly impactful for users who primarily or exclusively use mobile devices for development.
Solution:
I have introduced a toggle button on the mobile view of the p5.js web editor.
Allowing users to switch between the "Code" and "Preview" views even while a sketch is running.
And i have also made sure that the "Code" tab switches to "Output" tab when running the Code (As it was previously).
Implementation of Solution:
A new React component,
ShowOutputButton
, is created. This button manages the toggling logic and displays either "Show Code" or "Show Output" depending on the current view.The
showOutput
state variable, managed usinguseState
, tracks the active view (either code or preview).A
useEffect
hook synchronizes theshowOutput
state with theide.isPlaying
state. When the sketch starts (ide.isPlaying
is true), the view defaults to "Output" (showOutput
is true). When the sketch stops (ide.isPlaying
is false), the view defaults to "Code" (showOutput
is false). This ensures a sensible default view when starting and stopping sketches.The
ShowOutputButton
component is integrated into the UI.The
PreviewWrapper
andEditorSidebarWrapper
components are conditionally rendered based on theshowOutput
state. This ensures that only the selected view (Code or Preview) is displayed at a time.Here is a video of the working of the button:
https://github.com/user-attachments/assets/f8262fea-6a84-4f09-94fe-bb2dc68637f8
I have verified that this pull request:
npm run lint
)npm run test
)develop
branch.Fixes #123