-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
iOS issue: Modal closes immediately after launch #1913
Comments
@stephanieelliott .I have solved this issue in many project.I have also bid on your upwork post. solution to problem: |
@stephanieelliott I couldn’t find the modal A in the master branch. Is it yet to be merged? Or am I missing something? |
inside the function that assigned to the onShow props, The state that holds the modal visible value is set to false, causing the modal to vanish after it has been seen. |
Hi @barun1997, thanks for mentioning this. The issue is occurring on a branch that has not yet been merged and I've added the details to the description. Please note that as this issue is not yet merged we will need to keep any potential PR on hold. |
The problem comes from the next view that appears after the modal closes is another kind of modal - action sheet (ios). If it was up to me I would merge the pending PR (if there are no other issues in there). You could swap the Here are some interesting things about the 2nd modal. It's an ActionSheetIOS managed from inside the If you want to preserve the same UI you can use something like this: https://github.com/expo/react-native-action-sheet works on ios/android/web. I've used id precisely to present the choices "Camera", "Gallery" in a project of mine (pure react-native, the lib doesn't depend on expo). If you check the props it supports Another approach is again not to rely on |
FYI, we have merged the PR now, so you should be able to reproduce locally. Thanks for your proposal @kidroca. Ideally we would use our own option-picker UI rather than the iOS style action-sheet, which didn't exist when we implemented ImagePicker. But as this s built on top of Modal, we would still have the Modal issue. Because of this, our ideal proposal would provide a solution to the 2-modal problem, rather than replace the second Modal with another component. We will most likely like to use the same 2-Modal pattern elsewhere in the app. Does anyone have a proposal for this? @adnan1naeem @muratti32 you responded but haven't yet shared a proposal. |
Thanks for the info @Julesssss What you have planned would actually work if you use a Modal for the 2nd menu, as long as it's not an Action Sheet I've played around with this and narrowed the problem to precisely the Modal closes -> Action Sheet opens transition. ProposalMy proposal is to implement an option-picker UI that will replace the current So that you can reuse If that's undesired and you have a specific design for a Attachment Picker Modal I can implement it based on your For the curious: Details about why Modal to Modal works but Modal to ActionSheet does notThe reason why it would work with Modal to Modal transition is Modals in react native (ios) are implemented to wait for each other - it seems a workflow like modal to modal was anticipated or kind of get covered by the fact that ios does not allow more than one modals at once (ux antipattern) so if more than one modals happen to be active at the same time the 2nd one will be shown after the first one closes. But a Modal to ActionSheet seems to not have been anticipated - the ActionSheet takes over the view that is just about to get destroyed and results in |
Thanks for your updated proposal!
Let's await feedback from the design team to confirm what type of UI we should use here to replace the default Hey @Expensify/design, we're looking to replace the native-style attachment UI that is used on mobile (we need to update to fix a bug in the library and can no longer use the built in UI). We didn't have a consistent component style when we originally implemented this, so it's a good chance to redo this properly. Could you suggest a replacement? Perhaps we have a preference for custom or native UI here? This will only be displayed on mobile -- here is what this currently looks like: |
I believe that's exactly what @kidroca had in mind here:
Sounds good to me! |
Yep, it's pretty close to I see 2 easy approaches: The question is do you prefer the Like: const MENU_ITEMS = {
[CONST.MENU_ITEM_KEYS.TAKE_PHOTO]: {
icon: Camera,
text: 'Take Photo',
},
...
} And just provide a prop like: menuOptions={[
CONST.MENU_ITEM_KEYS.TAKE_PHOTO,
CONST.MENU_ITEM_KEYS.GALLERY,
CONST.MENU_ITEM_KEYS.GALLERY,
]} The attachment options could come from a new mapping like My idea is no matter which approach is selected to create a replacement component for |
@kidroca - Thank you for your solution, I have sent sent you the job on upwork. We look forward to your pull request. |
Hi @kidroca,
A colleague has a similar issue and has created a new MenuComponent for their new menu. Let's just do that for now, and we'll worry about refactoring them into a single Component later on (out of scope of this PR). |
Ok, so create a standalone component, encapsulating attachment options and delegating rendering to the Thanks for the reference |
Yeah, exactly 👍 |
@shawnborton I need to get the "Camera" and the "Picture" icons (svg), they are yet to be added to the current assets. I don't know where to find them? |
@Julesssss // in componentDidUpdate
if (
(prevProps.modal.isVisible && !this.props.modal.isVisible)
|| (prevProps.reportID !== this.props.reportID)
) {
this.setIsFocused(true);
}
// in setIsFocused
if (shouldHighlight && this.textInput) {
this.textInput.focus();
} This is causing a few side effects:
The decision to fix #1855 is to make These unintentional side effects are (I guess) why some code styles flag We want to bring focus back to the input after an attachment is selected so the user don't have to manually tap it -> this can happen by bringing focus back from here: <AttachmentModal
title="Upload Attachment"
onModalHide={() => this.setIsFocused(true)} // my change
onConfirm={(file) => {
addAction(this.props.reportID, '', file);
this.setTextInputShouldClear(false);
}}
> We want to bring focus back to the input if the field was focused prior to displaying a modal -> This already happens automatically on mobile (without the logic in I think I've covered most of the "critical" cases regarding bringing back focus to the text input in my code without adding much changes and without relying on |
…revent bugs Unwanted side effects coming from `componentDidUpdate` and global `modal.isVisible` Details: Expensify#1913 (comment)
Hi @kidroca,
It looks like you worked out the reason yourself, but yeah -- this was to allow us to keep the ReportActionCompose Component focused -- originally this was to regain focus after launching the attachment modal (there was only one modal at this point) -- and has led to multiple side effects as we built out the app as you have seen. Ideally, we desire this behaviour for any modal that is launched while the ReportActionCompose is on screen. While your solution works for the attachment Modal, I don't think it would cover other cases. For example: Tapping the FAB and launching 'new chat' Modal, then closing it by tapping outside. Do you have any idea whether this is solvable? My only question is whether your solution might have changed at all since the discussion around the HOC on 1855? |
So far my solution, which I'm yet to push 😅, seems to work good on mobile (specifically iOS, need to test Android).
For web though, the focus is only brought back to the input after selecting an attachment. So pressing the FAB and deciding to bail would not bring you back to the field, is that what you mean? My personal preference as a user is if I haven't been with the keyboard up when a modal opens I don't expect to be when it closes - with the exception of selecting an attachment this is convenient!
If you totally must keep the currently intended functionality - focus on the input after any modal close (while you are inside a chat), regardless of whether focus was on the field or not yes, it's still possible, but it will require slight restructuring: Instead of having a
In This will flatten the render structure a bit: <AttachmentModal>{/* This is the only modal that can keep a renderProp */}
<Touchable onPress={() => setMenuStage(MENU)}>
<CreateMenu isVisible={menuStage == MENU} onItemSelected={item => {/* Decide how to change menuStage */}} />
<AttachmentPicker isVisible={menuStage == ATTACHMENT} onClose={() => setMenuStage(CLOSED)} />
</AttachmentModal> I'll have to change the interface of the Another direction can be to add some My current solution doesn't not depend much on the outcome of #1855 - the problem is our own modals are triggering the Sidenote, most good chats that I've used seems to remember whether I had focus prior to leaving the char or not. When I open a chat it will initially show with the keyboard collapsed so I can view more of the conversation, but if I had focus prior to leaving this conversation, it will focus the field and show the keyboard |
Yeah.. but I can see this being tricky, and this is out of scope of this current issue considering we don't currently do this.
No you're right, I totally agree with this as a mobile user. I wouldn't want the keyboard to display when opening --The focus|showKeyboard events were separate though aren't they? So can't we request focus, leaving the mobile keyboard hidden? (I thought that was the default, until the user taps in the field again)
Thanks for sharing this solution, I think this too would require further discussions, so as mentioned above, I think for now we could keep the scope to the original issue + ensuring that focus remains after AttachmentPicker is hidden. |
When a modal opens the keyboard would always hide - it won't be visible under the modal When we call I'm talking about iOS specifically, on mobile Safari you can press "done" to hide the keyboard but focus is lost too |
Hi, This is Kaushik here. I would like to put a technical and pretty self explanatory solution for this.
|
@kaushiktd thanks for your suggestion, but that is our current solution and we are trying to remove this workaround. |
…revent bugs Unwanted side effects coming from `componentDidUpdate` and global `modal.isVisible` Details: Expensify#1913 (comment)
If you haven’t already, check out our contributing guidelines for onboarding!
Expected Result:
Add attachment
modal should remain open until dismissed.Actual Result:
Add Attachment
modal closes immediately when we attempt to display it. This only seems to occur when we attempt to launch Modal B from a callback within Modal AAction Performed:
At present, we've applied a temporary fix for this issue by using setTimeout to delay the launching of the second Modal However, that fix is sub-optimal and we are seeking a better permanent solution. See screen recording for a demo of the issue.
Add Attachment
to launch Modal BAdd Attachment
modal (Modal B) closes immediatelyNotes
This is the location of the problem/workaround.
Platform:
iOS
Version Number: 1.0.2-89
Videos:
E.cash157543.mov
The text was updated successfully, but these errors were encountered: