Giter Club home page Giter Club logo

Comments (6)

izyumkin avatar izyumkin commented on July 30, 2024 4

Thanks a lot! I'll add macOS support soonπŸ™

from mcemojipicker.

ygee07 avatar ygee07 commented on July 30, 2024 1

This is where I got it from
https://github.com/Remotionco/Emoji-Library-and-Utilities

I just extracted the getAllEmojis() and its dependencies, then just quickly made my own, though not as elegant as your library.

struct MacEmojiPicker: View {
    @Binding var selection: String
    @State private var showPicker: Bool = false
    
    var body: some View {
        YVButtonIcon(selection, emoji: true) {
            showPicker.toggle()
        }
        .sheet(isPresented: $showPicker) {
            pickerView
                .padding()
        }
    }
    
    var pickerView: some View {
        ScrollView {
            let items = getAllEmojis()
            let columns: [GridItem] = Array(repeating: GridItem(.flexible(minimum: 50, maximum: 240), spacing: 10), count: 8)
            
            
            LazyVGrid(columns: columns, spacing: 10) {
                ForEach(0 ..< items.count, id: \.self) { index in
                    Text(items[index].emoji)
                        .font(.largeTitle)
                        .contentShape(.circle)
                        .onTapGesture {
                            selection = items[index].emoji
                            showPicker.toggle()
                        }
                }
            }
        }
        .scrollIndicators(.hidden)
    }
    
    func getAllEmojis() -> [Emoji] {
        let emojiData = (try? Data(contentsOf: Bundle.main.url(forResource: "Emoji Unicode 15.0", withExtension: "json")!))!
        let data = try! JSONDecoder().decode([Emoji].self, from: emojiData)
        return data
        
    }
}

public struct Emoji: Decodable, Equatable {
    public let emoji: String
    public let description: String
    public let category: EmojiCategory
    public let aliases: [String]
    public let tags: [String]
    public let supportsSkinTones: Bool
    public let iOSVersion: String
    
    /// Get a string representation of this emoji with another skin tone
    /// - Parameter withSkinTone: new skin tone to use
    /// - Returns: a string of the new emoji with the applied skin tone
//    public func emoji (_ withSkinTone: EmojiSkinTone?) -> String? {
//        // Applying skin tones with Dan Wood's code: https://github.com/Remotionco/Emoji-Library-and-Utilities
//        
//        if !supportsSkinTones { return nil }
//        // If skin tone is nil, return the default yellow emoji
//        guard let withSkinTone = withSkinTone else {
//            if let unicode = emoji.unicodeScalars.first { return String(unicode) }
//            else { return emoji }
//        }
//        
//        var wasToneInserted = false
//        guard let toneScalar = Unicode.Scalar(withSkinTone.rawValue) else { return nil }
//
//        var scalars = [UnicodeScalar]()
//        // Either replace first found Fully Qualified 0xFE0F, or add to the end or before the first ZWJ, 0x200D.
//        for scalar in emoji.unicodeScalars {
//            if !wasToneInserted {
//                switch scalar.value {
//                case 0xFE0F:
//                    scalars.append(toneScalar) // tone scalar goes in place of the FE0F.
//                    wasToneInserted = true
//                case 0x200D:
//                    scalars.append(toneScalar) // Insert the tone selector
//                    scalars.append(scalar) // and then the ZWJ afterwards.
//                    wasToneInserted = true
//                default:
//                    scalars.append(scalar)
//                }
//            } else { // already handled tone, just append the other selectors it finds.
//                scalars.append(scalar)
//            }
//        }
//
//        if !wasToneInserted {
//            scalars.append(toneScalar) // Append at the end if needed.
//        }
//        
//        var string = ""
//        scalars.forEach({ string.append($0.description) })
//        return string
//    }
    
    enum CodingKeys: CodingKey {
        case emoji
        case description
        case category
        case aliases
        case tags
        case skin_tones
        case ios_version
    }
    
    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.emoji = try container.decode(String.self, forKey: .emoji)
        self.description = try container.decode(String.self, forKey: .description)
        self.category = try container.decode(EmojiCategory.self, forKey: .category)
        self.aliases = try container.decode([String].self, forKey: .aliases)
        self.tags = try container.decode([String].self, forKey: .tags)
        self.supportsSkinTones = try container.decodeIfPresent(Bool.self, forKey: .skin_tones) ?? false
        self.iOSVersion = try container.decode(String.self, forKey: .ios_version)
    }
    
    /// Create an instance of an emoji
    /// - Parameters:
    ///    - emoji: string representation of this emoji
    ///    - description: unicode textual description
    ///    - category: unicode category of this emoji
    ///    - aliases: similar names for this emoji
    ///    - tags: this emojis tags used for search
    ///    - supportsSkinTones: weather this emoji supports skin tones
    ///    - iOSVersion: the earliest iOS which supports this emoji
    public init (emoji: String, description: String, category: EmojiCategory, aliases: [String], tags: [String], supportsSkinTones: Bool, iOSVersion: String) {
        self.emoji = emoji
        self.description = description
        self.category = category
        self.aliases = aliases
        self.tags = tags
        self.supportsSkinTones = supportsSkinTones
        self.iOSVersion = iOSVersion
    }
}

public enum EmojiSkinTone: String, CaseIterable {
    case Light = "🏻"
    case MediumLight = "🏼"
    case Medium = "🏽"
    case MediumDark = "🏾"
    case Dark = "🏿"
}

public enum EmojiCategory: String, CaseIterable, Decodable {
    case SmileysAndEmotion = "Smileys & Emotion"
    case PeopleAndBody = "People & Body"
    case AnimalsAndNature = "Animals & Nature"
    case FoodAndDrink = "Food & Drink"
    case TravelAndPlaces = "Travel & Places"
    case Activities = "Activities"
    case Objects = "Objects"
    case Symbols = "Symbols"
    case Flags = "Flags"
}

from mcemojipicker.

naingminoo99 avatar naingminoo99 commented on July 30, 2024 1

Thank you I am also waiting for MacOS support

from mcemojipicker.

izyumkin avatar izyumkin commented on July 30, 2024

This is the second issue about macOS support I think I will add support after all.

If you can, please share the emoji picker you are using now. It would definitely make my work easier.

from mcemojipicker.

SattamAltwaim avatar SattamAltwaim commented on July 30, 2024

Hi, any updates? πŸ‘€

from mcemojipicker.

MagicFlow29 avatar MagicFlow29 commented on July 30, 2024

Hey any updates on this? Happy to help

from mcemojipicker.

chansencc avatar chansencc commented on July 30, 2024

Any update on this?

from mcemojipicker.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.