diff --git a/package-lock.json b/package-lock.json index 8cb5ff77..e3895b39 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.23.8", + "version": "1.23.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 6ed7271e..195c729c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-pspdfkit", - "version": "1.23.8", + "version": "1.23.9", "description": "A React Native module for the PSPDFKit library.", "keywords": [ "react native", diff --git a/samples/Catalog/package.json b/samples/Catalog/package.json index 0453b8c5..50ff4d69 100644 --- a/samples/Catalog/package.json +++ b/samples/Catalog/package.json @@ -1,6 +1,6 @@ { "name": "Catalog", - "version": "1.23.8", + "version": "1.23.9", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start" diff --git a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/JsonUtils.cs b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/JsonUtils.cs index e8533fb1..73105df8 100644 --- a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/JsonUtils.cs +++ b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/JsonUtils.cs @@ -1,9 +1,11 @@ using System.Collections.Generic; +using Windows.UI; using Newtonsoft.Json.Linq; using PSPDFKit.Search; using PSPDFKitFoundation; using PSPDFKitFoundation.Search; using PSPDFKitNative; +using ReactNative.UIManager; namespace ReactNativePSPDFKit { @@ -131,5 +133,20 @@ private static JArray LibraryQueryReultToJson(LibraryQueryResult libraryQueryRes return pageNumbersJson; } + + internal static Color? ParserColor(JObject jObject, string propertyName) + { + if (TryGetNotNullValue(jObject, propertyName, out var jsonHighlightColor)) + { + return ColorHelpers.Parse(jsonHighlightColor.Value()); + } + + return null; + } + + internal static bool TryGetNotNullValue(JObject jObject, string propertyName, out JToken value) + { + return jObject.TryGetValue(propertyName, out value) && value.Type != JTokenType.Null; + } } } diff --git a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs index f3935c71..c1c5bbd7 100644 --- a/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs +++ b/windows/ReactNativePSPDFKit/ReactNativePSPDFKit/PSPDFKitViewManager.cs @@ -63,22 +63,23 @@ public void SetHideNavigationBar(PDFViewPage view, bool hideNavigationBar) public async void SetCustomCss(PDFViewPage view, JObject styleJObject) { var colorString = string.Empty; - if (styleJObject.ContainsKey("highlightColor")) + + var maybeHighlightColor = JsonUtils.ParserColor(styleJObject, "highlightColor"); + if (maybeHighlightColor.HasValue) { - var highlightColor = ColorHelpers.Parse(styleJObject["highlightColor"].Value()); - colorString += $" --primary: {highlightColor.ToHexWithoutAlpha()};\r\n"; + colorString += $" --primary: {maybeHighlightColor.Value.ToHexWithoutAlpha()};\r\n"; } - if (styleJObject.ContainsKey("primaryColor")) + var maybePrimaryColor = JsonUtils.ParserColor(styleJObject, "primaryColor"); + if (maybePrimaryColor.HasValue) { - var primaryColor = ColorHelpers.Parse(styleJObject["primaryColor"].Value()); - colorString += $" --primary-dark-1: {primaryColor.ToHexWithoutAlpha()};\r\n"; + colorString += $" --primary-dark-1: {maybePrimaryColor.Value.ToHexWithoutAlpha()};\r\n"; } - if (styleJObject.ContainsKey("primaryDarkColor")) + var maybePrimaryDarkColor = JsonUtils.ParserColor(styleJObject, "primaryDarkColor"); + if (maybePrimaryDarkColor.HasValue) { - var primaryDarkColor = ColorHelpers.Parse(styleJObject["primaryDarkColor"].Value()); - colorString += $" --primary-dark-2: {primaryDarkColor.ToHexWithoutAlpha()};\r\n"; + colorString += $" --primary-dark-2: {maybePrimaryDarkColor.Value.ToHexWithoutAlpha()};\r\n"; } if (colorString.Length > 0)