From 4002de40824d16fa340922cbe637effe5228945d Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 15 Jul 2026 12:30:55 +0800 Subject: [PATCH] fix(keyboard): support OnePlus PLB110 fallback --- .../__tests__/environment.test.ts | 16 +++++++ src/utils/__tests__/platform-detect.test.ts | 47 +++++++++++++++---- src/utils/platform-detect.ts | 16 ++++++- 3 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/hooks/use-keyboard-height/__tests__/environment.test.ts b/src/hooks/use-keyboard-height/__tests__/environment.test.ts index 7d56c35a..0aeb750f 100644 --- a/src/hooks/use-keyboard-height/__tests__/environment.test.ts +++ b/src/hooks/use-keyboard-height/__tests__/environment.test.ts @@ -117,4 +117,20 @@ describe("shouldEnableKeyboardAdaptation", () => { }); expect(shouldEnableKeyboardAdaptation(environment)).toBe(false); }); + + it("enables the fallback for OnePlus PLB110 Facebook in-app browser", () => { + const environment = getKeyboardAdaptEnvironment( + "Mozilla/5.0 (Linux; Android 15; PLB110 Build/AP3A.240617.008; wv) " + + "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " + + "Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A", + ); + + expect(environment).toMatchObject({ + isAndroid: true, + isOppoFamilyDevice: true, + isFacebookInAppBrowser: true, + isTargetAndroidFacebookDevice: true, + }); + expect(shouldEnableKeyboardAdaptation(environment)).toBe(true); + }); }); diff --git a/src/utils/__tests__/platform-detect.test.ts b/src/utils/__tests__/platform-detect.test.ts index b9722b42..439b2fea 100644 --- a/src/utils/__tests__/platform-detect.test.ts +++ b/src/utils/__tests__/platform-detect.test.ts @@ -1,23 +1,52 @@ import { describe, expect, it } from "vitest"; -import { PlatformDetector } from "../platform-detect"; +import { + isOnePlusKeyboardFallbackDevice, + PlatformDetector, +} from "../platform-detect"; + +function createOnePlusFacebookUa(model: string): string { + return ( + `Mozilla/5.0 (Linux; Android 15; ${model} Build/AP3A.240617.008; wv) ` + + "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " + + "Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A" + ); +} describe("PlatformDetector", () => { it("treats OnePlus PKC110 as an OPPO-family keyboard fallback device", () => { - const ua = - "Mozilla/5.0 (Linux; Android 15; OnePlus PKC110 Build/AP3A.240617.008; wv) " + - "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " + - "Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A"; + const ua = createOnePlusFacebookUa("PKC110"); + expect( + isOnePlusKeyboardFallbackDevice({ + model: "PKC110", + vendor: "OnePlus", + }), + ).toBe(true); + expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true); + }); + + it("treats OnePlus PLB110 as an OPPO-family keyboard fallback device", () => { + const ua = createOnePlusFacebookUa("PLB110"); + + expect( + isOnePlusKeyboardFallbackDevice({ + model: "PLB110", + vendor: "OnePlus", + }), + ).toBe(true); expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(true); }); it("does not treat other OnePlus models as OPPO-family fallback devices", () => { - const ua = - "Mozilla/5.0 (Linux; Android 15; NE2210 Build/AP3A.240617.008; wv) " + - "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 " + - "Chrome/126.0.0.0 Mobile Safari/537.36 FBAN/FB4A"; + const ua = createOnePlusFacebookUa("NE2210"); + expect( + isOnePlusKeyboardFallbackDevice({ + model: "NE2210", + vendor: "OnePlus", + }), + ).toBe(false); expect(PlatformDetector.isOppoFamilyDevice(ua)).toBe(false); }); diff --git a/src/utils/platform-detect.ts b/src/utils/platform-detect.ts index 11f568ff..2cc710bc 100644 --- a/src/utils/platform-detect.ts +++ b/src/utils/platform-detect.ts @@ -1,5 +1,7 @@ import { UAParser } from "ua-parser-js"; +const ONEPLUS_KEYBOARD_FALLBACK_MODELS = new Set(["PKC110", "PLB110"]); + export type PlatformName = "ios" | "android" | "desktop" | "unknown"; export interface PlatformInfo { @@ -98,7 +100,10 @@ export class PlatformDetector { `${info.deviceVendor} ${info.userAgent}`, ); if (isOnePlusFamily) { - return /\bPKC110\b/i.test(`${info.deviceModel} ${info.userAgent}`); + return isOnePlusKeyboardFallbackDevice({ + model: info.deviceModel, + vendor: info.deviceVendor, + }); } return /\b(OPPO|OPlus|ColorOS|CPH\d{3,})\b/i.test(target); } @@ -114,3 +119,12 @@ export class PlatformDetector { return navigator.platform === "MacIntel" && (navigator.maxTouchPoints ?? 0) > 1; } } + +export function isOnePlusKeyboardFallbackDevice( + device: { model: string; vendor: string }, +): boolean { + if (!/\bOnePlus\b/i.test(device.vendor)) return false; + return ONEPLUS_KEYBOARD_FALLBACK_MODELS.has( + device.model.trim().toUpperCase(), + ); +}