Skip to content

Commit

Permalink
Add MAX_EMOJI_VERSION per platform.
Browse files Browse the repository at this point in the history
  • Loading branch information
langleyd committed Oct 2, 2024
1 parent 0069db6 commit 074b389
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# emojibase-bindings

Kotlin, Swift and Web bindings for emojibase json.

### Requirements

+ Node LTS
+ Yarn Classic
- Node LTS
- Yarn Classic

### Installation

Expand All @@ -14,6 +15,13 @@ Run `./scripts/setup.sh` to install dependencies for this project.

Run `./scripts/generateJson.sh` to generate the emojibase.json assets

## Updating Emoji Version

1. Update the emojibase `emojibase` version in a [package.json](package.json) to one that support the required emoji version.
2. To update the emoji version web uses change `MAX_EMOJI_VERSION_WEB` in [src/emoji.ts](src/emoji.ts)(Element Web imports this file directly).
- **caveat**: This version should be changed in unison with the twemoji verison so that all emojis displayed in the picker can actually be rendered.
3. To update the emoji version iOS or Android use change `MAX_EMOJI_VERSION_ANDROID` or `MAX_EMOJI_VERSION_IOS` respectively in [scripts/generateJson.sh](scripts/generateJson.sh)(This script generates the `emojibase.json` file packaged with the iOS and Android packages)

## Releasing

Use "[Run workflow](https://github.com/matrix-org/emojibase-bindings/actions/workflows/release.yaml)".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ class ExampleInstrumentedTest {

@Test
fun testAllEmojisHaveShortcodes() {
assert(store.allEmojis.all { it.shortcodes.isNotEmpty() })
assert(store.allEmojis.all{ it.shortcodes.isNotEmpty() })
}

@Test
fun testDoesNotSupportEmoji151() {
// Check 🙂‍↔️ emoji is not present
assertNull(store.allEmojis.firstOrNull{ it.hexcode == "1F642-200D-2195-FE0F" })
}
}
2 changes: 1 addition & 1 deletion platforms/ios/Emojibase/Resources/emojibase.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions platforms/ios/EmojibaseTests/EmojibaseTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,10 @@ final class EmojibaseTests: XCTestCase {
//All emojis have a shortcode
XCTAssertTrue(store.allEmojis.allSatisfy({ $0.shortcodes.first != nil }))
}

func testSupportsEmoji151() async throws {
let store = try XCTUnwrap(store)
// Check 🙂‍↔️ emoji is present
XCTAssertEqual(store.allEmojis.first(where: {$0.hexcode == "1F642-200D-2194-FE0F"})?.label, "head shaking horizontally")
}
}
14 changes: 11 additions & 3 deletions scripts/generateJson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

set -e

yarn start
MAX_EMOJI_VERSION_ANDROID=15.0
MAX_EMOJI_VERSION_IOS=15.1

EMOJIJSON_FILE="build/emojibase.json"
SWIFT_PATH="platforms/ios/Emojibase/Resources"
KOTLIN_PATH="platforms/android/library/src/main/assets"
SWIFT_PATH="platforms/ios/Emojibase/Resources"

cp "$EMOJIJSON_FILE" "$SWIFT_PATH"
# generate android json
export MAX_EMOJI_VERSION=$MAX_EMOJI_VERSION_ANDROID
yarn start
mkdir -p "$KOTLIN_PATH" && cp "$EMOJIJSON_FILE" "$KOTLIN_PATH"

# generate ios json
export MAX_EMOJI_VERSION=$MAX_EMOJI_VERSION_IOS
yarn start
cp "$EMOJIJSON_FILE" "$SWIFT_PATH"
5 changes: 4 additions & 1 deletion src/emoji.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface Emoji extends Omit<CompactEmoji, "shortcodes"> {
shortcodes: string[];
}

const MAX_EMOJI_VERSION = 15.0;
const MAX_EMOJI_VERSION_WEB = 15.0;
const EMOJI_TO_VERSION = new Map<string, number>();
for (const [versionString, emojis] of Object.entries(VERSIONS)) {
const version = parseFloat(versionString);
Expand Down Expand Up @@ -75,6 +75,9 @@ export const DATA_BY_CATEGORY: Record<string, Emoji[]> = {
flags: [],
};

const MAX_EMOJI_VERSION: number =
parseFloat(<string>process.env.MAX_EMOJI_VERSION) || MAX_EMOJI_VERSION_WEB;
console.log(`emojibase MAX_EMOJI_VERSION ${MAX_EMOJI_VERSION}`);
// Store various mappings from unicode/emoticon/shortcode to the Emoji objects
export const EMOJI: Emoji[] = EMOJIBASE.filter((emojiData) => {
// filter emojis that are less than or equal to MAX_EMOJI_VERSION
Expand Down
2 changes: 1 addition & 1 deletion test/emoji-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe("Emojis", () => {
expect(getEmojiFromUnicode("🙂")?.hexcode).toBe("1F642");
});

it("that emojis greated than are not included MAX_EMOJI_VERSION", async () => {
it("that emojis with version greater than MAX_EMOJI_VERSION_WEB are not included", async () => {
expect(getEmojiFromUnicode("🙂‍↔️")?.hexcode).toBeUndefined();
});
});
Expand Down

0 comments on commit 074b389

Please sign in to comment.