izyumkin / MCEmojiPicker

👻 EmojiPicker. Emoji picker for iOS like on macOS. With SwiftUI support.
MIT License
287 stars 39 forks source link

Categories items multiply on colorScheme change in SwiftUI. #30

Open Hollycene opened 1 year ago

Hollycene commented 1 year ago

I noticed an unusual behavior where category items multiply when the colorScheme changes while the emojiPicker is open in SwiftUI using the .emojiPicker modifier. It appears that these categories multiply each time the colorScheme changes. image

Minimal Reproducible Example: XCode Version 14.2 (14C18), iOS 16.2

struct EmojiPickerTest: View {

    @State private var isEmojiPickerShown: Bool = false
    @State private var emoji: String = "😀"

    var body: some View {
        Button(emoji, action: { isEmojiPickerShown = true })
            .emojiPicker(isPresented: $isEmojiPickerShown,
                         selectedEmoji: $emoji)
    }
}

struct EmojiPickerTest_Previews: PreviewProvider {
    static var previews: some View {
        EmojiPickerTest()
    }
}

There is a workaround for the problem: manually dismiss the emojiPicker when colorScheme is changed using the onChange() modifier like this:

        .onChange(of: colorScheme, perform: { _ in
            isEmojiPickerShown = false
        })

However, I believe the issue is still worth mentioning.

Jsmith4523 commented 2 months ago

Same issue I'm having and didn't know was already submitted. This appears to be a application state issue as well; as exiting then reopening the application with the view controller open will cause this issue as well