From 0e9a4c0a9bac6223f6bca76d53b03b791b5281af Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 13:34:28 +0100 Subject: [PATCH 1/9] chore: remove unused TemplateHelpers functions --- __tests__/exports.ts | 25 +------ scripts/utils/TemplateHelpers.ts | 119 ------------------------------- 2 files changed, 2 insertions(+), 142 deletions(-) diff --git a/__tests__/exports.ts b/__tests__/exports.ts index 9207fed77..87f7badbb 100644 --- a/__tests__/exports.ts +++ b/__tests__/exports.ts @@ -32,42 +32,21 @@ describe("Package Exports", () => { "BackgroundLayer", "RasterLayer", - // sources + // Sources "VectorSource", "ShapeSource", "RasterSource", "ImageSource", "Images", - // constants + // Constants "UserTrackingMode", "UserLocationRenderMode", "StyleURL", // "EventTypes", "CameraModes", "StyleSource", - // "InterpolationMode", "LineJoin", - // "LineCap", - // "LineTranslateAnchor", - // "CirclePitchScale", - // "CircleTranslateAnchor", - // 'CirclePitchAlignment', - // "FillExtrusionTranslateAnchor", - // "FillTranslateAnchor", - // "IconRotationAlignment", - // "IconTextFit", - // 'IconAnchor', - // "IconTranslateAnchor", - // 'IconPitchAlignment', - // "SymbolPlacement", - // "TextAnchor", - // "TextJustify", - // "TextPitchAlignment", - // "TextRotationAlignment", - // "TextTransform", - // "TextTranslateAnchor", - // "LightAnchor", "OfflinePackDownloadState", // "OfflineCallbackName", diff --git a/scripts/utils/TemplateHelpers.ts b/scripts/utils/TemplateHelpers.ts index 6146466de..e7fc81f70 100644 --- a/scripts/utils/TemplateHelpers.ts +++ b/scripts/utils/TemplateHelpers.ts @@ -50,13 +50,6 @@ export function exists(value: T): value is NonNullable { return typeof value !== "undefined" && value !== null; } -export function getValue(value: any, defaultValue: any) { - if (!exists(value) || value === "") { - return defaultValue; - } - return value; -} - export function camelCase(str: string, delimiter = "-") { const parts = str.split(delimiter); return parts @@ -123,10 +116,6 @@ export function ifOrElseIf(index: number) { return "} else if"; } -export function iosStringArrayLiteral(array: string[]) { - return `@[@${array.map((item) => `"${item}"`).join(", @")}]`; -} - export function iosPropName(name: string) { if (name.indexOf("visibility") !== -1) { return "visible"; @@ -140,14 +129,6 @@ export function iosPropName(name: string) { return name; } -export function iosMapLibrePropName(name: string) { - const result = iosPropName(name); - if (result === "fillExtrusionVerticalGradient") { - return "fillExtrusionHasVerticalGradient"; - } - return undefined; -} - export function iosPropMethodName(layer: any, name: string) { if (name.indexOf("Visibility") !== -1) { return pascalCase(layer.name) + "StyleLayer" + name; @@ -172,23 +153,6 @@ export function androidInputType(type: string, value?: string): string { } } -export function androidOutputType(type: string, value?: any): string { - if (type === "array" && value) { - return `${androidOutputType(value)}[]`; - } - - switch (type) { - case "color": - return "String"; - case "boolean": - return "Boolean"; - case "number": - return "Float"; - default: - return "String"; - } -} - export function androidGetConfigType(androidType: string, prop: any) { switch (androidType) { case "Integer": @@ -234,21 +198,6 @@ export function jsStyleType(prop: any) { return "StyleTypes.Constant"; } -export function jsDocPropRequires(prop: any) { - if (!prop.doc.requires) { - return undefined; - } - - let desc = ""; - for (const item of prop.doc.requires) { - if (typeof item === "string") { - desc += item + ", "; - } - } - - return desc; -} - export function getEnums(layers: any[]) { const result: Record = {}; @@ -315,12 +264,6 @@ export function dtsInterfaceType(prop: any) { throw new Error(`Unexpected type: ${prop.type} for ${prop.name}`); } - /* - if (prop.allowedFunctionTypes && prop.allowedFunctionTypes.length > 0) { - propTypes.push('StyleFunctionProps'); - } - */ - if (propTypes.length > 1) { return `${propTypes.map((p) => startAtSpace(4, p)).join(" | ")}, ${startAtSpace(2, "")}`; @@ -339,60 +282,6 @@ ${startAtSpace(2, "")}`; } } -export function jsDocReactProp(prop: any) { - const propTypes = []; - - if (prop.type === "color") { - propTypes.push("PropTypes.string"); - } else if (prop.type === "array") { - switch (prop.value) { - case "number": - propTypes.push("PropTypes.arrayOf(PropTypes.number)"); - break; - case "boolean": - propTypes.push("PropTypes.arrayOf(PropTypes.bool)"); - break; - case "string": - propTypes.push("PropTypes.arrayOf(PropTypes.string)"); - break; - default: - propTypes.push("PropTypes.array"); - } - } else if (prop.type === "number") { - propTypes.push("PropTypes.number"); - } else if (prop.type === "boolean") { - propTypes.push("PropTypes.bool"); - } else if (prop.type === "enum") { - if (prop.doc.values) { - propTypes.push( - `PropTypes.oneOf([${Object.keys(prop.doc.values) - .map((v) => `'${v}'`) - .join(", ")}])`, - ); - } else { - propTypes.push("PropTypes.any"); - } - } else { - // images can be required which result in a number - if (prop.image) { - propTypes.push("PropTypes.number"); - } - propTypes.push("PropTypes.string"); - } - - if (prop.expressionSupported && !propTypes.includes("PropTypes.array")) { - propTypes.push("PropTypes.array"); - } - - if (propTypes.length > 1) { - return `PropTypes.oneOfType([ -${propTypes.map((p) => startAtSpace(4, p)).join(",\n")}, -${startAtSpace(2, "])")}`; - } else { - return propTypes[0]; - } -} - export function startAtSpace(spaceCount: number, str: string) { let value = ""; @@ -407,14 +296,6 @@ export function replaceNewLine(str: string) { return str?.replace(/\n/g, "
"); } -export function styleMarkdownTableRow(style: any) { - return `| \`${style.name}\` | \`${style.type}\` | \`${ - style.requires.join(", ") || "none" - }\` | \`${style.disabledBy.join(", ") || "none"}\` | ${replaceNewLine( - style.description, - )} |`; -} - export function methodMarkdownTableRow(method: any) { return method.params .map((param: any) => { From ec930a1bd0db1890028bbc71652b46f27a42fe09 Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 13:35:48 +0100 Subject: [PATCH 2/9] refactor: remove mapbox stylesheet from MLRNStyle --- .../maplibre/reactnative/components/styles/MLRNStyle.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyle.java b/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyle.java index bc8662e56..3d8220dc5 100644 --- a/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyle.java +++ b/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyle.java @@ -35,10 +35,7 @@ public List getAllStyleKeys() { while (it.hasNextKey()) { String key = it.nextKey(); - - if (!key.equals("__MAPBOX_STYLESHEET__")) { - keys.add(key); - } + keys.add(key); } return keys; From 369d0f1c88911736ac85a4f68aa1f7f5ff5173b1 Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 13:36:03 +0100 Subject: [PATCH 3/9] refactor: cleanup MLRNStyleFactory --- .../components/styles/MLRNStyleFactory.java | 21 +++++++++---------- scripts/templates/MLRNStyleFactory.java.ejs | 3 +-- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyleFactory.java b/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyleFactory.java index 010493296..e9054992f 100644 --- a/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyleFactory.java +++ b/android/src/main/java/org/maplibre/reactnative/components/styles/MLRNStyleFactory.java @@ -9,7 +9,6 @@ import org.maplibre.android.style.layers.FillLayer; import org.maplibre.android.style.layers.LineLayer; import org.maplibre.android.style.layers.PropertyFactory; -import org.maplibre.android.style.layers.PropertyValue; import org.maplibre.android.style.layers.RasterLayer; import org.maplibre.android.style.layers.SymbolLayer; import org.maplibre.android.style.layers.HeatmapLayer; @@ -28,7 +27,7 @@ public class MLRNStyleFactory { public static void setFillLayerStyle(final FillLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -89,7 +88,7 @@ public void onAllImagesLoaded() { public static void setLineLayerStyle(final LineLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -186,7 +185,7 @@ public void onAllImagesLoaded() { public static void setSymbolLayerStyle(final SymbolLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -409,7 +408,7 @@ public void onAllImagesLoaded() { public static void setCircleLayerStyle(final CircleLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -486,7 +485,7 @@ public static void setCircleLayerStyle(final CircleLayer layer, MLRNStyle style) public static void setHeatmapLayerStyle(final HeatmapLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -527,7 +526,7 @@ public static void setHeatmapLayerStyle(final HeatmapLayer layer, MLRNStyle styl public static void setFillExtrusionLayerStyle(final FillExtrusionLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -591,7 +590,7 @@ public void onAllImagesLoaded() { public static void setRasterLayerStyle(final RasterLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -650,7 +649,7 @@ public static void setRasterLayerStyle(final RasterLayer layer, MLRNStyle style) public static void setHillshadeLayerStyle(final HillshadeLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -697,7 +696,7 @@ public static void setHillshadeLayerStyle(final HillshadeLayer layer, MLRNStyle public static void setBackgroundLayerStyle(final BackgroundLayer layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } @@ -737,7 +736,7 @@ public void onAllImagesLoaded() { public static void setLightLayerStyle(final Light layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } diff --git a/scripts/templates/MLRNStyleFactory.java.ejs b/scripts/templates/MLRNStyleFactory.java.ejs index 4a692ab25..978ea4ecd 100644 --- a/scripts/templates/MLRNStyleFactory.java.ejs +++ b/scripts/templates/MLRNStyleFactory.java.ejs @@ -13,7 +13,6 @@ import org.maplibre.android.style.layers.FillExtrusionLayer; import org.maplibre.android.style.layers.FillLayer; import org.maplibre.android.style.layers.LineLayer; import org.maplibre.android.style.layers.PropertyFactory; -import org.maplibre.android.style.layers.PropertyValue; import org.maplibre.android.style.layers.RasterLayer; import org.maplibre.android.style.layers.SymbolLayer; import org.maplibre.android.style.layers.HeatmapLayer; @@ -33,7 +32,7 @@ public class MLRNStyleFactory { public static void <%- helpers.setLayerMethodName(layer) -%>(final <%- helpers.getLayerType(layer, 'android') -%> layer, MLRNStyle style) { List styleKeys = style.getAllStyleKeys(); - if (styleKeys.size() == 0) { + if (styleKeys.isEmpty()) { return; } From 69112473f7a01b513b56785abf44f5afa25ab718 Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 13:49:11 +0100 Subject: [PATCH 4/9] feat: replace enums with string types --- scripts/templates/MapLibreRNStyles.ts.ejs | 12 - scripts/utils/TemplateHelpers.ts | 31 +- src/utils/MapLibreRNStyles.d.ts | 443 +++------------------- 3 files changed, 67 insertions(+), 419 deletions(-) diff --git a/scripts/templates/MapLibreRNStyles.ts.ejs b/scripts/templates/MapLibreRNStyles.ts.ejs index 14eff92a6..a78c9d91f 100644 --- a/scripts/templates/MapLibreRNStyles.ts.ejs +++ b/scripts/templates/MapLibreRNStyles.ts.ejs @@ -61,18 +61,6 @@ export type Value = | T | Expression; -<%_ for (let enumInfo of helpers.getEnums(layers)) { _%> - enum <%- helpers.pascalCase(enumInfo.name) %>Enum { - <%_ for (let k of Object.keys(enumInfo.values)) { _%> - /** <%- enumInfo.values[k].doc %> */ - <%- helpers.pascalCase(k) %> = '<%- k %>', - <%_ } _%> - } - type <%- helpers.pascalCase(enumInfo.name) %>EnumValues = <%- Object.keys(enumInfo.values).map(k => `'${k}'`).join(' | ') %>; -<%_ } _%> - -type Enum = EnumType | EnumValues; - <%_ for (let layer of layers) { _%> export interface <%- helpers.pascalCase(layer.name) %>LayerStyleProps { <%_ for (let prop of layer.properties) { _%> diff --git a/scripts/utils/TemplateHelpers.ts b/scripts/utils/TemplateHelpers.ts index e7fc81f70..f3b8171a6 100644 --- a/scripts/utils/TemplateHelpers.ts +++ b/scripts/utils/TemplateHelpers.ts @@ -198,25 +198,6 @@ export function jsStyleType(prop: any) { return "StyleTypes.Constant"; } -export function getEnums(layers: any[]) { - const result: Record = {}; - - layers.forEach((layer) => { - layer.properties.forEach((property: any) => { - if ( - property.type === "enum" || - (property.type === "array" && property.value === "enum") - ) { - result[property.name] = { - values: property.doc.values, - name: property.name, - }; - } - }); - }); - return Object.values(result); -} - export function dtsInterfaceType(prop: any) { const propTypes: string[] = []; @@ -224,7 +205,6 @@ export function dtsInterfaceType(prop: any) { propTypes.push("Translation"); } else if (prop.type === "color") { propTypes.push("string"); - // propTypes.push('ConstantPropType'); } else if (prop.type === "array") { switch (prop.value) { case "number": @@ -238,18 +218,19 @@ export function dtsInterfaceType(prop: any) { break; case "enum": propTypes.push( - `Enum<${pascalCase(prop.name)}Enum, ${pascalCase( - prop.name, - )}EnumValues>[]`, + `(${Object.keys(prop.doc.values) + .map((value) => `"${value}"`) + .join(" | ")})[]`, ); break; } - // propTypes.push('ConstantPropType'); } else if (prop.type === "number") { propTypes.push("number"); } else if (prop.type === "enum") { propTypes.push( - `Enum<${pascalCase(prop.name)}Enum, ${pascalCase(prop.name)}EnumValues>`, + Object.keys(prop.doc.values) + .map((value) => `"${value}"`) + .join(" | "), ); } else if (prop.type === "boolean") { propTypes.push("boolean"); diff --git a/src/utils/MapLibreRNStyles.d.ts b/src/utils/MapLibreRNStyles.d.ts index 65f3b40d6..61d37f413 100644 --- a/src/utils/MapLibreRNStyles.d.ts +++ b/src/utils/MapLibreRNStyles.d.ts @@ -134,299 +134,6 @@ export type Value = | T | Expression; -export enum VisibilityEnum { - /** The layer is shown. */ - Visible = "visible", - /** The layer is not shown. */ - None = "none", -} -type VisibilityEnumValues = "visible" | "none"; -export enum FillTranslateAnchorEnum { - /** The fill is translated relative to the map. */ - Map = "map", - /** The fill is translated relative to the viewport. */ - Viewport = "viewport", -} -type FillTranslateAnchorEnumValues = "map" | "viewport"; -export enum LineCapEnum { - /** A cap with a squared-off end which is drawn to the exact endpoint of the line. */ - Butt = "butt", - /** A cap with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. */ - Round = "round", - /** A cap with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. */ - Square = "square", -} -type LineCapEnumValues = "butt" | "round" | "square"; -export enum LineJoinEnum { - /** A join with a squared-off end which is drawn beyond the endpoint of the line at a distance of one-half of the line's width. */ - Bevel = "bevel", - /** A join with a rounded end which is drawn beyond the endpoint of the line at a radius of one-half of the line's width and centered on the endpoint of the line. */ - Round = "round", - /** A join with a sharp, angled corner which is drawn with the outer sides beyond the endpoint of the path until they meet. */ - Miter = "miter", -} -type LineJoinEnumValues = "bevel" | "round" | "miter"; -export enum LineTranslateAnchorEnum { - /** The line is translated relative to the map. */ - Map = "map", - /** The line is translated relative to the viewport. */ - Viewport = "viewport", -} -type LineTranslateAnchorEnumValues = "map" | "viewport"; -export enum SymbolPlacementEnum { - /** The label is placed at the point where the geometry is located. */ - Point = "point", - /** The label is placed along the line of the geometry. Can only be used on `LineString` and `Polygon` geometries. */ - Line = "line", - /** The label is placed at the center of the line of the geometry. Can only be used on `LineString` and `Polygon` geometries. Note that a single feature in a vector tile may contain multiple line geometries. */ - LineCenter = "line-center", -} -type SymbolPlacementEnumValues = "point" | "line" | "line-center"; -export enum SymbolZOrderEnum { - /** Sorts symbols by `symbol-sort-key` if set. Otherwise, sorts symbols by their y-position relative to the viewport if `icon-allow-overlap` or `text-allow-overlap` is set to `true` or `icon-ignore-placement` or `text-ignore-placement` is `false`. */ - Auto = "auto", - /** Sorts symbols by their y-position relative to the viewport if `icon-allow-overlap` or `text-allow-overlap` is set to `true` or `icon-ignore-placement` or `text-ignore-placement` is `false`. */ - ViewportY = "viewport-y", - /** Sorts symbols by `symbol-sort-key` if set. Otherwise, no sorting is applied; symbols are rendered in the same order as the source data. */ - Source = "source", -} -type SymbolZOrderEnumValues = "auto" | "viewport-y" | "source"; -export enum IconRotationAlignmentEnum { - /** When `symbol-placement` is set to `point`, aligns icons east-west. When `symbol-placement` is set to `line` or `line-center`, aligns icon x-axes with the line. */ - Map = "map", - /** Produces icons whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbol-placement`. */ - Viewport = "viewport", - /** When `symbol-placement` is set to `point`, this is equivalent to `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is equivalent to `map`. */ - Auto = "auto", -} -type IconRotationAlignmentEnumValues = "map" | "viewport" | "auto"; -export enum IconTextFitEnum { - /** The icon is displayed at its intrinsic aspect ratio. */ - None = "none", - /** The icon is scaled in the x-dimension to fit the width of the text. */ - Width = "width", - /** The icon is scaled in the y-dimension to fit the height of the text. */ - Height = "height", - /** The icon is scaled in both x- and y-dimensions. */ - Both = "both", -} -type IconTextFitEnumValues = "none" | "width" | "height" | "both"; -export enum IconAnchorEnum { - /** The center of the icon is placed closest to the anchor. */ - Center = "center", - /** The left side of the icon is placed closest to the anchor. */ - Left = "left", - /** The right side of the icon is placed closest to the anchor. */ - Right = "right", - /** The top of the icon is placed closest to the anchor. */ - Top = "top", - /** The bottom of the icon is placed closest to the anchor. */ - Bottom = "bottom", - /** The top left corner of the icon is placed closest to the anchor. */ - TopLeft = "top-left", - /** The top right corner of the icon is placed closest to the anchor. */ - TopRight = "top-right", - /** The bottom left corner of the icon is placed closest to the anchor. */ - BottomLeft = "bottom-left", - /** The bottom right corner of the icon is placed closest to the anchor. */ - BottomRight = "bottom-right", -} -type IconAnchorEnumValues = - | "center" - | "left" - | "right" - | "top" - | "bottom" - | "top-left" - | "top-right" - | "bottom-left" - | "bottom-right"; -export enum IconPitchAlignmentEnum { - /** The icon is aligned to the plane of the map. */ - Map = "map", - /** The icon is aligned to the plane of the viewport. */ - Viewport = "viewport", - /** Automatically matches the value of `icon-rotation-alignment`. */ - Auto = "auto", -} -type IconPitchAlignmentEnumValues = "map" | "viewport" | "auto"; -export enum TextPitchAlignmentEnum { - /** The text is aligned to the plane of the map. */ - Map = "map", - /** The text is aligned to the plane of the viewport. */ - Viewport = "viewport", - /** Automatically matches the value of `text-rotation-alignment`. */ - Auto = "auto", -} -type TextPitchAlignmentEnumValues = "map" | "viewport" | "auto"; -export enum TextRotationAlignmentEnum { - /** When `symbol-placement` is set to `point`, aligns text east-west. When `symbol-placement` is set to `line` or `line-center`, aligns text x-axes with the line. */ - Map = "map", - /** Produces glyphs whose x-axes are aligned with the x-axis of the viewport, regardless of the value of `symbol-placement`. */ - Viewport = "viewport", - /** When `symbol-placement` is set to `point`, aligns text to the x-axis of the viewport. When `symbol-placement` is set to `line` or `line-center`, aligns glyphs to the x-axis of the viewport and places them along the line. */ - ViewportGlyph = "viewport-glyph", - /** When `symbol-placement` is set to `point`, this is equivalent to `viewport`. When `symbol-placement` is set to `line` or `line-center`, this is equivalent to `map`. */ - Auto = "auto", -} -type TextRotationAlignmentEnumValues = - | "map" - | "viewport" - | "viewport-glyph" - | "auto"; -export enum TextJustifyEnum { - /** The text is aligned towards the anchor position. */ - Auto = "auto", - /** The text is aligned to the left. */ - Left = "left", - /** The text is centered. */ - Center = "center", - /** The text is aligned to the right. */ - Right = "right", -} -type TextJustifyEnumValues = "auto" | "left" | "center" | "right"; -export enum TextVariableAnchorEnum { - /** The center of the text is placed closest to the anchor. */ - Center = "center", - /** The left side of the text is placed closest to the anchor. */ - Left = "left", - /** The right side of the text is placed closest to the anchor. */ - Right = "right", - /** The top of the text is placed closest to the anchor. */ - Top = "top", - /** The bottom of the text is placed closest to the anchor. */ - Bottom = "bottom", - /** The top left corner of the text is placed closest to the anchor. */ - TopLeft = "top-left", - /** The top right corner of the text is placed closest to the anchor. */ - TopRight = "top-right", - /** The bottom left corner of the text is placed closest to the anchor. */ - BottomLeft = "bottom-left", - /** The bottom right corner of the text is placed closest to the anchor. */ - BottomRight = "bottom-right", -} -type TextVariableAnchorEnumValues = - | "center" - | "left" - | "right" - | "top" - | "bottom" - | "top-left" - | "top-right" - | "bottom-left" - | "bottom-right"; -export enum TextAnchorEnum { - /** The center of the text is placed closest to the anchor. */ - Center = "center", - /** The left side of the text is placed closest to the anchor. */ - Left = "left", - /** The right side of the text is placed closest to the anchor. */ - Right = "right", - /** The top of the text is placed closest to the anchor. */ - Top = "top", - /** The bottom of the text is placed closest to the anchor. */ - Bottom = "bottom", - /** The top left corner of the text is placed closest to the anchor. */ - TopLeft = "top-left", - /** The top right corner of the text is placed closest to the anchor. */ - TopRight = "top-right", - /** The bottom left corner of the text is placed closest to the anchor. */ - BottomLeft = "bottom-left", - /** The bottom right corner of the text is placed closest to the anchor. */ - BottomRight = "bottom-right", -} -type TextAnchorEnumValues = - | "center" - | "left" - | "right" - | "top" - | "bottom" - | "top-left" - | "top-right" - | "bottom-left" - | "bottom-right"; -export enum TextWritingModeEnum { - /** If a text's language supports horizontal writing mode, symbols with point placement would be laid out horizontally. */ - Horizontal = "horizontal", - /** If a text's language supports vertical writing mode, symbols with point placement would be laid out vertically. */ - Vertical = "vertical", -} -type TextWritingModeEnumValues = "horizontal" | "vertical"; -export enum TextTransformEnum { - /** The text is not altered. */ - None = "none", - /** Forces all letters to be displayed in uppercase. */ - Uppercase = "uppercase", - /** Forces all letters to be displayed in lowercase. */ - Lowercase = "lowercase", -} -type TextTransformEnumValues = "none" | "uppercase" | "lowercase"; -export enum IconTranslateAnchorEnum { - /** Icons are translated relative to the map. */ - Map = "map", - /** Icons are translated relative to the viewport. */ - Viewport = "viewport", -} -type IconTranslateAnchorEnumValues = "map" | "viewport"; -export enum TextTranslateAnchorEnum { - /** The text is translated relative to the map. */ - Map = "map", - /** The text is translated relative to the viewport. */ - Viewport = "viewport", -} -type TextTranslateAnchorEnumValues = "map" | "viewport"; -export enum CircleTranslateAnchorEnum { - /** The circle is translated relative to the map. */ - Map = "map", - /** The circle is translated relative to the viewport. */ - Viewport = "viewport", -} -type CircleTranslateAnchorEnumValues = "map" | "viewport"; -export enum CirclePitchScaleEnum { - /** Circles are scaled according to their apparent distance to the camera. */ - Map = "map", - /** Circles are not scaled. */ - Viewport = "viewport", -} -type CirclePitchScaleEnumValues = "map" | "viewport"; -export enum CirclePitchAlignmentEnum { - /** The circle is aligned to the plane of the map. */ - Map = "map", - /** The circle is aligned to the plane of the viewport. */ - Viewport = "viewport", -} -type CirclePitchAlignmentEnumValues = "map" | "viewport"; -export enum FillExtrusionTranslateAnchorEnum { - /** The fill extrusion is translated relative to the map. */ - Map = "map", - /** The fill extrusion is translated relative to the viewport. */ - Viewport = "viewport", -} -type FillExtrusionTranslateAnchorEnumValues = "map" | "viewport"; -export enum RasterResamplingEnum { - /** (Bi)linear filtering interpolates pixel values using the weighted average of the four closest original source pixels creating a smooth but blurry look when overscaled */ - Linear = "linear", - /** Nearest neighbor filtering interpolates pixel values using the nearest original source pixel creating a sharp but pixelated look when overscaled */ - Nearest = "nearest", -} -type RasterResamplingEnumValues = "linear" | "nearest"; -export enum HillshadeIlluminationAnchorEnum { - /** The hillshade illumination is relative to the north direction. */ - Map = "map", - /** The hillshade illumination is relative to the top of the viewport. */ - Viewport = "viewport", -} -type HillshadeIlluminationAnchorEnumValues = "map" | "viewport"; -export enum AnchorEnum { - /** The position of the light source is aligned to the rotation of the map. */ - Map = "map", - /** The position of the light source is aligned to the rotation of the viewport. */ - Viewport = "viewport", -} -type AnchorEnumValues = "map" | "viewport"; - -type Enum = EnumType | EnumValues; - export interface FillLayerStyleProps { /** * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. @@ -435,7 +142,7 @@ export interface FillLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * Whether or not the fill should be antialiased. */ @@ -485,10 +192,7 @@ export interface FillLayerStyleProps { * * @requires fillTranslate */ - fillTranslateAnchor?: Value< - Enum, - ["zoom"] - >; + fillTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; /** * Name of image in sprite to use for drawing image fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. */ @@ -503,11 +207,11 @@ export interface LineLayerStyleProps { /** * The display of line endings. */ - lineCap?: Value, ["zoom"]>; + lineCap?: Value<"butt" | "round" | "square", ["zoom"]>; /** * The display of lines when joining. */ - lineJoin?: Value, ["zoom", "feature"]>; + lineJoin?: Value<"bevel" | "round" | "miter", ["zoom", "feature"]>; /** * Used to automatically convert miter joins to bevel joins for sharp angles. */ @@ -523,7 +227,7 @@ export interface LineLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * The opacity at which the line will be drawn. */ @@ -558,10 +262,7 @@ export interface LineLayerStyleProps { * * @requires lineTranslate */ - lineTranslateAnchor?: Value< - Enum, - ["zoom"] - >; + lineTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; /** * Stroke thickness. */ @@ -629,10 +330,7 @@ export interface SymbolLayerStyleProps { /** * Label placement relative to its geometry. */ - symbolPlacement?: Value< - Enum, - ["zoom"] - >; + symbolPlacement?: Value<"point" | "line" | "line-center", ["zoom"]>; /** * Distance between two symbol anchors. */ @@ -648,10 +346,7 @@ export interface SymbolLayerStyleProps { /** * Determines whether overlapping symbols in the same layer are rendered in the order that they appear in the data source or by their yPosition relative to the viewport. To control the order and prioritization of symbols otherwise, use `symbolSortKey`. */ - symbolZOrder?: Value< - Enum, - ["zoom"] - >; + symbolZOrder?: Value<"auto" | "viewport-y" | "source", ["zoom"]>; /** * If true, the icon will be visible even if it collides with other previously drawn symbols. * @@ -677,10 +372,7 @@ export interface SymbolLayerStyleProps { * * @requires iconImage */ - iconRotationAlignment?: Value< - Enum, - ["zoom"] - >; + iconRotationAlignment?: Value<"map" | "viewport" | "auto", ["zoom"]>; /** * Scales the original size of the icon by the provided factor. The new pixel size of the image will be the original pixel size multiplied by `iconSize`. 1 is the original size; 3 triples the size of the image. * @@ -692,7 +384,7 @@ export interface SymbolLayerStyleProps { * * @requires iconImage, textField */ - iconTextFit?: Value, ["zoom"]>; + iconTextFit?: Value<"none" | "width" | "height" | "both", ["zoom"]>; /** * Size of the additional area added to dimensions determined by `iconTextFit`, in clockwise order: top, right, bottom, left. * @@ -733,7 +425,15 @@ export interface SymbolLayerStyleProps { * @requires iconImage */ iconAnchor?: Value< - Enum, + | "center" + | "left" + | "right" + | "top" + | "bottom" + | "top-left" + | "top-right" + | "bottom-left" + | "bottom-right", ["zoom", "feature"] >; /** @@ -741,26 +441,20 @@ export interface SymbolLayerStyleProps { * * @requires iconImage */ - iconPitchAlignment?: Value< - Enum, - ["zoom"] - >; + iconPitchAlignment?: Value<"map" | "viewport" | "auto", ["zoom"]>; /** * Orientation of text when map is pitched. * * @requires textField */ - textPitchAlignment?: Value< - Enum, - ["zoom"] - >; + textPitchAlignment?: Value<"map" | "viewport" | "auto", ["zoom"]>; /** * In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. * * @requires textField */ textRotationAlignment?: Value< - Enum, + "map" | "viewport" | "viewport-glyph" | "auto", ["zoom"] >; /** @@ -803,7 +497,7 @@ export interface SymbolLayerStyleProps { * @requires textField */ textJustify?: Value< - Enum, + "auto" | "left" | "center" | "right", ["zoom", "feature"] >; /** @@ -818,7 +512,17 @@ export interface SymbolLayerStyleProps { * @requires textField */ textVariableAnchor?: Value< - Enum[], + ( + | "center" + | "left" + | "right" + | "top" + | "bottom" + | "top-left" + | "top-right" + | "bottom-left" + | "bottom-right" + )[], ["zoom"] >; /** @@ -829,7 +533,15 @@ export interface SymbolLayerStyleProps { * @disabledBy textVariableAnchor */ textAnchor?: Value< - Enum, + | "center" + | "left" + | "right" + | "top" + | "bottom" + | "top-left" + | "top-right" + | "bottom-left" + | "bottom-right", ["zoom", "feature"] >; /** @@ -843,10 +555,7 @@ export interface SymbolLayerStyleProps { * * @requires textField */ - textWritingMode?: Value< - Enum[], - ["zoom"] - >; + textWritingMode?: Value<("horizontal" | "vertical")[], ["zoom"]>; /** * Rotates the text clockwise. * @@ -871,7 +580,7 @@ export interface SymbolLayerStyleProps { * @requires textField */ textTransform?: Value< - Enum, + "none" | "uppercase" | "lowercase", ["zoom", "feature"] >; /** @@ -905,7 +614,7 @@ export interface SymbolLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * The opacity at which the icon will be drawn. * @@ -979,10 +688,7 @@ The unit is in pixels only for SDF sprites that were created with a blur radius * * @requires iconImage, iconTranslate */ - iconTranslateAnchor?: Value< - Enum, - ["zoom"] - >; + iconTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; /** * The opacity at which the text will be drawn. * @@ -1054,10 +760,7 @@ The unit is in pixels only for SDF sprites that were created with a blur radius * * @requires textField, textTranslate */ - textTranslateAnchor?: Value< - Enum, - ["zoom"] - >; + textTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; } export interface CircleLayerStyleProps { /** @@ -1067,7 +770,7 @@ export interface CircleLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * Circle radius. */ @@ -1118,24 +821,15 @@ export interface CircleLayerStyleProps { * * @requires circleTranslate */ - circleTranslateAnchor?: Value< - Enum, - ["zoom"] - >; + circleTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; /** * Controls the scaling behavior of the circle when the map is pitched. */ - circlePitchScale?: Value< - Enum, - ["zoom"] - >; + circlePitchScale?: Value<"map" | "viewport", ["zoom"]>; /** * Orientation of circle when map is pitched. */ - circlePitchAlignment?: Value< - Enum, - ["zoom"] - >; + circlePitchAlignment?: Value<"map" | "viewport", ["zoom"]>; /** * The width of the circle's stroke. Strokes are placed outside of the `circleRadius`. */ @@ -1168,7 +862,7 @@ export interface HeatmapLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * Radius of influence of one heatmap point in pixels. Increasing the value makes the heatmap smoother, but less detailed. */ @@ -1209,7 +903,7 @@ export interface FillExtrusionLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * The opacity of the entire fill extrusion layer. This is rendered on a perLayer, not perFeature, basis, and dataDriven styling is not available. */ @@ -1244,13 +938,7 @@ export interface FillExtrusionLayerStyleProps { * * @requires fillExtrusionTranslate */ - fillExtrusionTranslateAnchor?: Value< - Enum< - FillExtrusionTranslateAnchorEnum, - FillExtrusionTranslateAnchorEnumValues - >, - ["zoom"] - >; + fillExtrusionTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; /** * Name of image in sprite to use for drawing images on extruded fills. For seamless patterns, image width and height must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. */ @@ -1289,7 +977,7 @@ export interface RasterLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * The opacity at which the image will be drawn. */ @@ -1347,10 +1035,7 @@ export interface RasterLayerStyleProps { /** * The resampling/interpolation method to use for overscaling, also known as texture magnification filter */ - rasterResampling?: Value< - Enum, - ["zoom"] - >; + rasterResampling?: Value<"linear" | "nearest", ["zoom"]>; /** * Fade duration when a new tile is added, or when a video is started or its coordinates are updated. */ @@ -1360,7 +1045,7 @@ export interface HillshadeLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * The direction of the light source used to generate the hillshading with 0 as the top of the viewport if `hillshadeIlluminationAnchor` is set to `viewport` and due north if `hillshadeIlluminationAnchor` is set to `map`. */ @@ -1368,13 +1053,7 @@ export interface HillshadeLayerStyleProps { /** * Direction of light source when map is rotated. */ - hillshadeIlluminationAnchor?: Value< - Enum< - HillshadeIlluminationAnchorEnum, - HillshadeIlluminationAnchorEnumValues - >, - ["zoom"] - >; + hillshadeIlluminationAnchor?: Value<"map" | "viewport", ["zoom"]>; /** * Intensity of the hillshade */ @@ -1416,7 +1095,7 @@ export interface BackgroundLayerStyleProps { /** * Whether this layer is displayed. */ - visibility?: Enum; + visibility?: "visible" | "none"; /** * The color with which the background will be drawn. * @@ -1451,7 +1130,7 @@ export interface LightLayerStyleProps { /** * Whether extruded geometries are lit relative to the map or viewport. */ - anchor?: Value, ["zoom"]>; + anchor?: Value<"map" | "viewport", ["zoom"]>; /** * Position of the light source relative to lit (extruded) geometries, in [r radial coordinate, a azimuthal angle, p polar angle] where r indicates the distance from the center of the base of an object to its light, a indicates the position of the light relative to 0° (0° when `light.anchor` is set to `viewport` corresponds to the top of the viewport, or 0° when `light.anchor` is set to `map` corresponds to due north, and degrees proceed clockwise), and p indicates the height of the light (from 0°, directly above, to 180°, directly below). */ From fb5bc4f58260657adfd76b04f5590d2390ea76db Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 15:27:26 +0100 Subject: [PATCH 5/9] feat: remove native style enums from module --- __tests__/exports.ts | 6 +- .../reactnative/modules/MLRNModule.java | 145 ------------------ ios/MLRN/MLRNModule.m | 135 ---------------- jest-setup.ts | 34 ---- src/MLRNModule.ts | 15 +- 5 files changed, 7 insertions(+), 328 deletions(-) diff --git a/__tests__/exports.ts b/__tests__/exports.ts index 87f7badbb..2edaf945f 100644 --- a/__tests__/exports.ts +++ b/__tests__/exports.ts @@ -42,14 +42,10 @@ describe("Package Exports", () => { // Constants "UserTrackingMode", "UserLocationRenderMode", - "StyleURL", - // "EventTypes", "CameraModes", + "StyleURL", "StyleSource", - "LineJoin", - "OfflinePackDownloadState", - // "OfflineCallbackName", // Methods diff --git a/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java b/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java index 4ea0c9398..b35d8741f 100644 --- a/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java +++ b/android/src/main/java/org/maplibre/reactnative/modules/MLRNModule.java @@ -11,9 +11,7 @@ import com.facebook.react.module.annotations.ReactModule; import org.maplibre.android.MapLibre; import org.maplibre.android.WellKnownTileServer; -import org.maplibre.android.style.layers.Property; import org.maplibre.reactnative.components.camera.constants.CameraMode; -import org.maplibre.reactnative.components.styles.MLRNStyleValue; import org.maplibre.reactnative.components.styles.sources.MLRNSource; import org.maplibre.reactnative.events.constants.EventTypes; import org.maplibre.reactnative.http.CustomHeadersInterceptor; @@ -99,127 +97,6 @@ public Map getConstants() { Map styleSourceConsts = new HashMap<>(); styleSourceConsts.put("DefaultSourceID", MLRNSource.DEFAULT_ID); - // interpolation modes - Map interpolationModes = new HashMap<>(); - interpolationModes.put("Exponential", MLRNStyleValue.InterpolationModeExponential); - interpolationModes.put("Categorical", MLRNStyleValue.InterpolationModeCategorical); - interpolationModes.put("Interval", MLRNStyleValue.InterpolationModeInterval); - interpolationModes.put("Identity", MLRNStyleValue.InterpolationModeIdentity); - - // line layer constants - Map lineJoin = new HashMap<>(); - lineJoin.put("Bevel", Property.LINE_JOIN_BEVEL); - lineJoin.put("Round", Property.LINE_JOIN_ROUND); - lineJoin.put("Miter", Property.LINE_JOIN_MITER); - - Map lineCap = new HashMap<>(); - lineCap.put("Butt", Property.LINE_CAP_BUTT); - lineCap.put("Round", Property.LINE_CAP_ROUND); - lineCap.put("Square", Property.LINE_CAP_SQUARE); - - Map lineTranslateAnchor = new HashMap<>(); - lineTranslateAnchor.put("Map", Property.LINE_TRANSLATE_ANCHOR_MAP); - lineTranslateAnchor.put("Viewport", Property.LINE_TRANSLATE_ANCHOR_VIEWPORT); - - // circle layer constants - Map circlePitchScale = new HashMap<>(); - circlePitchScale.put("Map", Property.CIRCLE_PITCH_SCALE_MAP); - circlePitchScale.put("Viewport", Property.CIRCLE_PITCH_SCALE_VIEWPORT); - - Map circleTranslateAnchor = new HashMap<>(); - circleTranslateAnchor.put("Map", Property.CIRCLE_TRANSLATE_ANCHOR_MAP); - circleTranslateAnchor.put("Viewport", Property.CIRCLE_TRANSLATE_ANCHOR_VIEWPORT); - - Map circlePitchAlignment = new HashMap<>(); - circlePitchAlignment.put("Map", Property.CIRCLE_PITCH_ALIGNMENT_MAP); - circlePitchAlignment.put("Viewport", Property.CIRCLE_PITCH_ALIGNMENT_VIEWPORT); - - // fill extrusion layer constants - Map fillExtrusionTranslateAnchor = new HashMap<>(); - fillExtrusionTranslateAnchor.put("Map", Property.FILL_EXTRUSION_TRANSLATE_ANCHOR_MAP); - fillExtrusionTranslateAnchor.put("Viewport", Property.FILL_EXTRUSION_TRANSLATE_ANCHOR_VIEWPORT); - - // fill layer constants - Map fillTranslateAnchor = new HashMap<>(); - fillTranslateAnchor.put("Map", Property.FILL_TRANSLATE_ANCHOR_MAP); - fillTranslateAnchor.put("Viewport", Property.FILL_TRANSLATE_ANCHOR_VIEWPORT); - - // symbol layer constants - Map iconRotationAlignment = new HashMap<>(); - iconRotationAlignment.put("Auto", Property.ICON_ROTATION_ALIGNMENT_AUTO); - iconRotationAlignment.put("Map", Property.ICON_ROTATION_ALIGNMENT_MAP); - iconRotationAlignment.put("Viewport", Property.ICON_ROTATION_ALIGNMENT_VIEWPORT); - - Map iconTextFit = new HashMap<>(); - iconTextFit.put("None", Property.ICON_TEXT_FIT_NONE); - iconTextFit.put("Width", Property.ICON_TEXT_FIT_WIDTH); - iconTextFit.put("Height", Property.ICON_TEXT_FIT_HEIGHT); - iconTextFit.put("Both", Property.ICON_TEXT_FIT_BOTH); - - Map iconAnchor = new HashMap<>(); - iconAnchor.put("Center", Property.ICON_ANCHOR_CENTER); - iconAnchor.put("Left", Property.ICON_ANCHOR_LEFT); - iconAnchor.put("Right", Property.ICON_ANCHOR_RIGHT); - iconAnchor.put("Top", Property.ICON_ANCHOR_TOP); - iconAnchor.put("Bottom", Property.ICON_ANCHOR_BOTTOM); - iconAnchor.put("TopLeft", Property.ICON_ANCHOR_TOP_LEFT); - iconAnchor.put("TopRight", Property.ICON_ANCHOR_TOP_RIGHT); - iconAnchor.put("BottomLeft", Property.ICON_ANCHOR_BOTTOM_LEFT); - iconAnchor.put("BottomRight", Property.ICON_ANCHOR_BOTTOM_RIGHT); - - Map iconPitchAlignment = new HashMap<>(); - iconPitchAlignment.put("Auto", Property.ICON_PITCH_ALIGNMENT_AUTO); - iconPitchAlignment.put("Map", Property.ICON_PITCH_ALIGNMENT_MAP); - iconPitchAlignment.put("Viewport", Property.ICON_PITCH_ALIGNMENT_VIEWPORT); - - Map iconTranslateAnchor = new HashMap<>(); - iconTranslateAnchor.put("Map", Property.ICON_TRANSLATE_ANCHOR_MAP); - iconTranslateAnchor.put("Viewport", Property.ICON_TRANSLATE_ANCHOR_VIEWPORT); - - Map symbolPlacement = new HashMap<>(); - symbolPlacement.put("Line", Property.SYMBOL_PLACEMENT_LINE); - symbolPlacement.put("Point", Property.SYMBOL_PLACEMENT_POINT); - - Map textAnchor = new HashMap<>(); - textAnchor.put("Center", Property.TEXT_ANCHOR_CENTER); - textAnchor.put("Left", Property.TEXT_ANCHOR_LEFT); - textAnchor.put("Right", Property.TEXT_ANCHOR_RIGHT); - textAnchor.put("Top", Property.TEXT_ANCHOR_TOP); - textAnchor.put("Bottom", Property.TEXT_ANCHOR_BOTTOM); - textAnchor.put("TopLeft", Property.TEXT_ANCHOR_TOP_LEFT); - textAnchor.put("TopRight", Property.TEXT_ANCHOR_TOP_RIGHT); - textAnchor.put("BottomLeft", Property.TEXT_ANCHOR_BOTTOM_LEFT); - textAnchor.put("BottomRight", Property.TEXT_ANCHOR_BOTTOM_RIGHT); - - Map textJustify = new HashMap<>(); - textJustify.put("Center", Property.TEXT_JUSTIFY_CENTER); - textJustify.put("Left", Property.TEXT_JUSTIFY_LEFT); - textJustify.put("Right", Property.TEXT_JUSTIFY_RIGHT); - - Map textPitchAlignment = new HashMap<>(); - textPitchAlignment.put("Auto", Property.TEXT_PITCH_ALIGNMENT_AUTO); - textPitchAlignment.put("Map", Property.TEXT_PITCH_ALIGNMENT_MAP); - textPitchAlignment.put("Viewport", Property.TEXT_PITCH_ALIGNMENT_VIEWPORT); - - Map textRotationAlignment = new HashMap<>(); - textRotationAlignment.put("Auto", Property.TEXT_ROTATION_ALIGNMENT_AUTO); - textRotationAlignment.put("Map", Property.TEXT_ROTATION_ALIGNMENT_MAP); - textRotationAlignment.put("Viewport", Property.TEXT_ROTATION_ALIGNMENT_VIEWPORT); - - Map textTransform = new HashMap<>(); - textTransform.put("None", Property.TEXT_TRANSFORM_NONE); - textTransform.put("Lowercase", Property.TEXT_TRANSFORM_LOWERCASE); - textTransform.put("Uppercase", Property.TEXT_TRANSFORM_UPPERCASE); - - Map textTranslateAnchor = new HashMap<>(); - textTranslateAnchor.put("Map", Property.TEXT_TRANSLATE_ANCHOR_MAP); - textTranslateAnchor.put("Viewport", Property.TEXT_TRANSLATE_ANCHOR_VIEWPORT); - - // light constants - Map lightAnchor = new HashMap<>(); - lightAnchor.put("Map", Property.ANCHOR_MAP); - lightAnchor.put("Viewport", Property.ANCHOR_VIEWPORT); - // offline region download states Map offlinePackDownloadStates = new HashMap<>(); offlinePackDownloadStates.put("Inactive", MLRNOfflineModule.INACTIVE_REGION_DOWNLOAD_STATE); @@ -242,28 +119,6 @@ public Map getConstants() { .put("UserLocationVerticalAlignment", userLocationVerticalAlignment) .put("CameraModes", cameraModes) .put("StyleSource", styleSourceConsts) - .put("InterpolationMode", interpolationModes) - .put("LineJoin", lineJoin) - .put("LineCap", lineCap) - .put("LineTranslateAnchor", lineTranslateAnchor) - .put("CirclePitchScale", circlePitchScale) - .put("CircleTranslateAnchor", circleTranslateAnchor) - .put("CirclePitchAlignment", circlePitchAlignment) - .put("FillExtrusionTranslateAnchor", fillExtrusionTranslateAnchor) - .put("FillTranslateAnchor", fillTranslateAnchor) - .put("IconRotationAlignment", iconRotationAlignment) - .put("IconTextFit", iconTextFit) - .put("IconTranslateAnchor", iconTranslateAnchor) - .put("SymbolPlacement", symbolPlacement) - .put("IconAnchor", iconAnchor) - .put("TextAnchor", textAnchor) - .put("TextJustify", textJustify) - .put("IconPitchAlignment", iconPitchAlignment) - .put("TextPitchAlignment", textPitchAlignment) - .put("TextRotationAlignment", textRotationAlignment) - .put("TextTransform", textTransform) - .put("TextTranslateAnchor", textTranslateAnchor) - .put("LightAnchor", lightAnchor) .put("OfflinePackDownloadState", offlinePackDownloadStates) .put("OfflineCallbackName", offlineModuleCallbackNames) .put("LocationCallbackName", locationModuleCallbackNames) diff --git a/ios/MLRN/MLRNModule.m b/ios/MLRN/MLRNModule.m index 7a5658788..33aa9359e 100644 --- a/ios/MLRN/MLRNModule.m +++ b/ios/MLRN/MLRNModule.m @@ -71,120 +71,6 @@ + (BOOL)requiresMainQueueSetup NSMutableDictionary *styleSourceConsts = [[NSMutableDictionary alloc] init]; [styleSourceConsts setObject:DEFAULT_SOURCE_ID forKey:@"DefaultSourceID"]; - // line layer constants - NSMutableDictionary *lineJoin = [[NSMutableDictionary alloc] init]; - [lineJoin setObject:@(MLNLineJoinBevel) forKey:@"Bevel"]; - [lineJoin setObject:@(MLNLineJoinRound) forKey:@"Round"]; - [lineJoin setObject:@(MLNLineJoinMiter) forKey:@"Miter"]; - - NSMutableDictionary *lineCap = [[NSMutableDictionary alloc] init]; - [lineCap setObject:@(MLNLineCapButt) forKey:@"Butt"]; - [lineCap setObject:@(MLNLineCapRound) forKey:@"Round"]; - [lineCap setObject:@(MLNLineCapSquare) forKey:@"Square"]; - - NSMutableDictionary *lineTranslateAnchor = [[NSMutableDictionary alloc] init]; - [lineTranslateAnchor setObject:@(MLNLineTranslationAnchorMap) forKey:@"Map"]; - [lineTranslateAnchor setObject:@(MLNLineTranslationAnchorViewport) forKey:@"Viewport"]; - - // circle layer constants - NSMutableDictionary *circlePitchScale = [[NSMutableDictionary alloc] init]; - [circlePitchScale setObject:@(MLNCircleScaleAlignmentMap) forKey:@"Map"]; - [circlePitchScale setObject:@(MLNCircleScaleAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *circlePitchAlignment = [[NSMutableDictionary alloc] init]; - [circlePitchAlignment setObject:@(MLNCirclePitchAlignmentMap) forKey:@"Map"]; - [circlePitchAlignment setObject:@(MLNCirclePitchAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *circleTranslateAnchor = [[NSMutableDictionary alloc] init]; - [circleTranslateAnchor setObject:@(MLNCircleTranslationAnchorMap) forKey:@"Map"]; - [circleTranslateAnchor setObject:@(MLNCircleTranslationAnchorViewport) forKey:@"Viewport"]; - - // fill extrusion layer constants - NSMutableDictionary *fillExtrusionTranslateAnchor = [[NSMutableDictionary alloc] init]; - [fillExtrusionTranslateAnchor setObject:@(MLNFillExtrusionTranslationAnchorMap) forKey:@"Map"]; - [fillExtrusionTranslateAnchor setObject:@(MLNFillExtrusionTranslationAnchorViewport) forKey:@"Viewport"]; - - // fill layer constants - NSMutableDictionary *fillTranslateAnchor = [[NSMutableDictionary alloc] init]; - [fillTranslateAnchor setObject:@(MLNFillTranslationAnchorMap) forKey:@"Map"]; - [fillTranslateAnchor setObject:@(MLNFillTranslationAnchorViewport) forKey:@"Viewport"]; - - // symbol layer constants - NSMutableDictionary *iconRotationAlignment = [[NSMutableDictionary alloc] init]; - [iconRotationAlignment setObject:@(MLNIconRotationAlignmentAuto) forKey:@"Auto"]; - [iconRotationAlignment setObject:@(MLNIconRotationAlignmentMap) forKey:@"Map"]; - [iconRotationAlignment setObject:@(MLNIconRotationAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *iconTextFit = [[NSMutableDictionary alloc] init]; - [iconTextFit setObject:@(MLNIconTextFitNone) forKey:@"None"]; - [iconTextFit setObject:@(MLNIconTextFitWidth) forKey:@"Width"]; - [iconTextFit setObject:@(MLNIconTextFitHeight) forKey:@"Height"]; - [iconTextFit setObject:@(MLNIconTextFitBoth) forKey:@"Both"]; - - NSMutableDictionary *iconAnchor = [[NSMutableDictionary alloc] init]; - [iconAnchor setObject:@(MLNIconAnchorCenter) forKey:@"Center"]; - [iconAnchor setObject:@(MLNIconAnchorTop) forKey:@"Top"]; - [iconAnchor setObject:@(MLNIconAnchorBottom) forKey:@"Bottom"]; - [iconAnchor setObject:@(MLNIconAnchorLeft) forKey:@"Left"]; - [iconAnchor setObject:@(MLNIconAnchorRight) forKey:@"Right"]; - [iconAnchor setObject:@(MLNIconAnchorTopLeft) forKey:@"TopLeft"]; - [iconAnchor setObject:@(MLNIconAnchorTopRight) forKey:@"TopRight"]; - [iconAnchor setObject:@(MLNIconAnchorBottomLeft) forKey:@"BottomLeft"]; - [iconAnchor setObject:@(MLNIconAnchorBottomRight) forKey:@"BottomRight"]; - - NSMutableDictionary *iconTranslateAnchor = [[NSMutableDictionary alloc] init]; - [iconTranslateAnchor setObject:@(MLNIconTranslationAnchorMap) forKey:@"Map"]; - [iconTranslateAnchor setObject:@(MLNIconTranslationAnchorViewport) forKey:@"Viewport"]; - - NSMutableDictionary *iconPitchAlignment = [[NSMutableDictionary alloc] init]; - [iconPitchAlignment setObject:@(MLNIconPitchAlignmentAuto) forKey:@"Auto"]; - [iconPitchAlignment setObject:@(MLNIconPitchAlignmentMap) forKey:@"Map"]; - [iconPitchAlignment setObject:@(MLNIconPitchAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *symbolPlacement = [[NSMutableDictionary alloc] init]; - [symbolPlacement setObject:@(MLNSymbolPlacementLine) forKey:@"Line"]; - [symbolPlacement setObject:@(MLNSymbolPlacementPoint) forKey:@"Point"]; - - NSMutableDictionary *textAnchor = [[NSMutableDictionary alloc] init]; - [textAnchor setObject:@(MLNTextAnchorCenter) forKey:@"Center"]; - [textAnchor setObject:@(MLNTextAnchorLeft) forKey:@"Left"]; - [textAnchor setObject:@(MLNTextAnchorRight) forKey:@"Right"]; - [textAnchor setObject:@(MLNTextAnchorTop) forKey:@"Top"]; - [textAnchor setObject:@(MLNTextAnchorBottom) forKey:@"Bottom"]; - [textAnchor setObject:@(MLNTextAnchorTopLeft) forKey:@"TopLeft"]; - [textAnchor setObject:@(MLNTextAnchorTopRight) forKey:@"TopRight"]; - [textAnchor setObject:@(MLNTextAnchorBottomLeft) forKey:@"BottomLeft"]; - [textAnchor setObject:@(MLNTextAnchorBottomRight) forKey:@"BottomRight"]; - - NSMutableDictionary *textJustify = [[NSMutableDictionary alloc] init]; - [textJustify setObject:@(MLNTextJustificationCenter) forKey:@"Center"]; - [textJustify setObject:@(MLNTextJustificationLeft) forKey:@"Left"]; - [textJustify setObject:@(MLNTextJustificationRight) forKey:@"Right"]; - - NSMutableDictionary *textPitchAlignment = [[NSMutableDictionary alloc] init]; - [textPitchAlignment setObject:@(MLNTextPitchAlignmentAuto) forKey:@"Auto"]; - [textPitchAlignment setObject:@(MLNTextPitchAlignmentMap) forKey:@"Map"]; - [textPitchAlignment setObject:@(MLNTextPitchAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *textRotationAlignment = [[NSMutableDictionary alloc] init]; - [textRotationAlignment setObject:@(MLNTextRotationAlignmentAuto) forKey:@"Auto"]; - [textRotationAlignment setObject:@(MLNTextRotationAlignmentMap) forKey:@"Map"]; - [textRotationAlignment setObject:@(MLNTextRotationAlignmentViewport) forKey:@"Viewport"]; - - NSMutableDictionary *textTransform = [[NSMutableDictionary alloc] init]; - [textTransform setObject:@(MLNTextTransformNone) forKey:@"None"]; - [textTransform setObject:@(MLNTextTransformLowercase) forKey:@"Lowercase"]; - [textTransform setObject:@(MLNTextTransformUppercase) forKey:@"Uppercase"]; - - NSMutableDictionary *textTranslateAnchor = [[NSMutableDictionary alloc] init]; - [textTranslateAnchor setObject:@(MLNTextTranslationAnchorMap) forKey:@"Map"]; - [textTranslateAnchor setObject:@(MLNTextTranslationAnchorViewport) forKey:@"Viewport"]; - - // light constants - NSMutableDictionary *lightAnchor = [[NSMutableDictionary alloc] init]; - [lightAnchor setObject:@(MLNLightAnchorMap) forKey:@"Map"]; - [lightAnchor setObject:@(MLNLightAnchorViewport) forKey:@"Viewport"]; - // offline module callback names NSMutableDictionary *offlineModuleCallbackNames = [[NSMutableDictionary alloc] init]; [offlineModuleCallbackNames setObject:RCT_MAPBOX_OFFLINE_CALLBACK_ERROR forKey:@"Error"]; @@ -202,27 +88,6 @@ + (BOOL)requiresMainQueueSetup @"UserLocationVerticalAlignment": userLocationVerticalAlignment, @"CameraModes": cameraModes, @"StyleSource": styleSourceConsts, - @"LineJoin": lineJoin, - @"LineCap": lineCap, - @"LineTranslateAnchor": lineTranslateAnchor, - @"CirclePitchScale": circlePitchScale, - @"CircleTranslateAnchor": circleTranslateAnchor, - @"CirclePitchAlignment": circlePitchAlignment, - @"FillExtrusionTranslateAnchor": fillExtrusionTranslateAnchor, - @"FillTranslateAnchor": fillTranslateAnchor, - @"IconRotationAlignment": iconRotationAlignment, - @"IconTextFit": iconTextFit, - @"IconTranslateAnchor": iconTranslateAnchor, - @"IconAnchor": iconAnchor, - @"IconPitchAlignment": iconPitchAlignment, - @"SymbolPlacement": symbolPlacement, - @"TextAnchor": textAnchor, - @"TextJustify": textJustify, - @"TextPitchAlignment": textPitchAlignment, - @"TextRotationAlignment": textRotationAlignment, - @"TextTransform": textTransform, - @"TextTranslateAnchor": textTranslateAnchor, - @"LightAnchor": lightAnchor, @"OfflineCallbackName": offlineModuleCallbackNames, @"OfflinePackDownloadState": offlinePackDownloadState, @"LocationCallbackName": locationModuleEvents diff --git a/jest-setup.ts b/jest-setup.ts index ee8540f41..cf33ba785 100644 --- a/jest-setup.ts +++ b/jest-setup.ts @@ -35,40 +35,6 @@ NativeModules.MLRNModule = { ]), CameraModes: keyMirror(["Flight", "Ease", "None"]), StyleSource: keyMirror(["DefaultSourceID"]), - InterpolationMode: keyMirror([ - "Exponential", - "Categorical", - "Interval", - "Identity", - ]), - LineJoin: keyMirror(["Bevel", "Round", "Miter"]), - LineCap: keyMirror(["Butt", "Round", "Square"]), - LineTranslateAnchor: keyMirror(["Map", "Viewport"]), - CirclePitchScale: keyMirror(["Map", "Viewport"]), - CircleTranslateAnchor: keyMirror(["Map", "Viewport"]), - FillExtrusionTranslateAnchor: keyMirror(["Map", "Viewport"]), - FillTranslateAnchor: keyMirror(["Map", "Viewport"]), - IconRotationAlignment: keyMirror(["Auto", "Map", "Viewport"]), - IconTextFit: keyMirror(["None", "Width", "Height", "Both"]), - IconTranslateAnchor: keyMirror(["Map", "Viewport"]), - SymbolPlacement: keyMirror(["Line", "Point"]), - TextAnchor: keyMirror([ - "Center", - "Left", - "Right", - "Top", - "Bottom", - "TopLeft", - "TopRight", - "BottomLeft", - "BottomRight", - ]), - TextJustify: keyMirror(["Center", "Left", "Right"]), - TextPitchAlignment: keyMirror(["Auto", "Map", "Viewport"]), - TextRotationAlignment: keyMirror(["Auto", "Map", "Viewport"]), - TextTransform: keyMirror(["None", "Lowercase", "Uppercase"]), - TextTranslateAnchor: keyMirror(["Map", "Viewport"]), - LightAnchor: keyMirror(["Map", "Viewport"]), OfflinePackDownloadState: keyMirror(["Inactive", "Active", "Complete"]), OfflineCallbackName: keyMirror(["Progress", "Error"]), diff --git a/src/MLRNModule.ts b/src/MLRNModule.ts index c628daa7e..59cab9a52 100644 --- a/src/MLRNModule.ts +++ b/src/MLRNModule.ts @@ -9,20 +9,18 @@ interface IMLRNModule { Linear: CameraMode.Linear; None: CameraMode.None; }; - StyleURL: { - Default: URL; - }; + OfflinePackDownloadState: { Inactive: string | number; Active: string | number; Complete: string | number; Unknown?: string | number; }; - LineJoin: { - Bevel: string | number; - Round: string | number; - Miter: string | number; + + StyleURL: { + Default: URL; }; + StyleSource: { DefaultSourceID: string; }; @@ -40,10 +38,9 @@ const MLRNModule: IMLRNModule = Object.create(NativeModules.MLRNModule); export const { CameraModes, - StyleURL, OfflinePackDownloadState, - LineJoin, StyleSource, + StyleURL, setAccessToken, getAccessToken, From e0013361f4ffff51faa68f464a2dce1cd1d6e358 Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 15:28:19 +0100 Subject: [PATCH 6/9] refactor: cleanup getStylePropertyType --- scripts/codegen.ts | 4 +- ...Map.ts.ejs => getStylePropertyType.ts.ejs} | 32 +-- scripts/utils/TemplateHelpers.ts | 12 +- src/utils/StyleValue.ts | 4 +- src/utils/getStylePropertyType.ts | 265 ++++++++++++++++++ src/utils/styleMap.ts | 265 ------------------ 6 files changed, 291 insertions(+), 291 deletions(-) rename scripts/templates/{styleMap.ts.ejs => getStylePropertyType.ts.ejs} (71%) create mode 100644 src/utils/getStylePropertyType.ts delete mode 100644 src/utils/styleMap.ts diff --git a/scripts/codegen.ts b/scripts/codegen.ts index fee15098b..581602a37 100644 --- a/scripts/codegen.ts +++ b/scripts/codegen.ts @@ -52,8 +52,8 @@ const TEMPLATE_MAPPINGS = [ output: path.join(ANDROID_OUTPUT_PATH, "MLRNStyleFactory.java"), }, { - input: path.join(TEMPLATES_PATH, "styleMap.ts.ejs"), - output: path.join(JS_OUTPUT_PATH, "styleMap.ts"), + input: path.join(TEMPLATES_PATH, "getStylePropertyType.ts.ejs"), + output: path.join(JS_OUTPUT_PATH, "getStylePropertyType.ts"), }, ]; diff --git a/scripts/templates/styleMap.ts.ejs b/scripts/templates/getStylePropertyType.ts.ejs similarity index 71% rename from scripts/templates/styleMap.ts.ejs rename to scripts/templates/getStylePropertyType.ts.ejs index bfdae141e..7f56fdece 100644 --- a/scripts/templates/styleMap.ts.ejs +++ b/scripts/templates/getStylePropertyType.ts.ejs @@ -8,7 +8,7 @@ import { isAndroid } from './index'; -export const StyleTypes = { +const StyleType = { Constant: 'constant', Color: 'color', Transition: 'transition', @@ -18,34 +18,24 @@ export const StyleTypes = { Enum: 'enum', }; -export function getStyleType(styleProp: keyof typeof styleExtras): string { - if (!isAndroid() && styleExtras[styleProp]) { - return styleExtras[styleProp].iosType; - } - if (styleMap[styleProp]) { - return styleMap[styleProp]; - } - throw new Error(`${styleProp} is not a valid MapLibre layer style`); -} - -const styleMap = { +const STYLE_MAP = { <%_ for (let layer of layers) { _%> <%_ for (let prop of layer.properties) { _%> <%_ if (prop.name !== 'visibility') { _%> <%= prop.name %>: <%- helpers.jsStyleType(prop) %>, <%_ if (prop.transition) { _%> - <%= prop.name %>Transition: StyleTypes.Transition, + <%= prop.name %>Transition: StyleType.Transition, <%_ } _%> <%_ } _%> <%_ } _%> <%_ } _%> - visibility: StyleTypes.Constant, + visibility: StyleType.Constant, }; -export const styleExtras = { +const STYLE_OVERRIDES = { // padding iconTextFitPadding: { iosType: 'edgeinsets', @@ -83,4 +73,14 @@ export const styleExtras = { }, }; -export default styleMap; +export function getStylePropertyType(styleProperty: keyof typeof STYLE_OVERRIDES): string { + if (!isAndroid() && STYLE_OVERRIDES[styleProperty]) { + return STYLE_OVERRIDES[styleProperty].iosType; + } + + if (STYLE_MAP[styleProperty]) { + return STYLE_MAP[styleProperty]; + } + + throw new Error(`${styleProperty} is not a valid MapLibre layer style`); +} diff --git a/scripts/utils/TemplateHelpers.ts b/scripts/utils/TemplateHelpers.ts index f3b8171a6..6c6c71a02 100644 --- a/scripts/utils/TemplateHelpers.ts +++ b/scripts/utils/TemplateHelpers.ts @@ -176,26 +176,26 @@ export function androidGetConfigType(androidType: string, prop: any) { export function jsStyleType(prop: any) { if (prop.type === "color") { - return "StyleTypes.Color"; + return "StyleType.Color"; } if (prop.type === "enum") { - return "StyleTypes.Enum"; + return "StyleType.Enum"; } if (prop.type === "string" && prop.image) { - return "StyleTypes.Image"; + return "StyleType.Image"; } if (prop.type === "resolvedImage") { - return "StyleTypes.Image"; + return "StyleType.Image"; } if (prop.name.indexOf("Translate") !== -1) { - return "StyleTypes.Translation"; + return "StyleType.Translation"; } - return "StyleTypes.Constant"; + return "StyleType.Constant"; } export function dtsInterfaceType(prop: any) { diff --git a/src/utils/StyleValue.ts b/src/utils/StyleValue.ts index cec2c0cde..aafd05386 100644 --- a/src/utils/StyleValue.ts +++ b/src/utils/StyleValue.ts @@ -5,7 +5,7 @@ import BridgeValue, { type StyleValueJSON, } from "./BridgeValue"; import { type AllLayerStyleProps } from "./MapLibreRNStyles"; -import { getStyleType } from "./styleMap"; +import { getStylePropertyType } from "./getStylePropertyType"; export type StyleValue = { styletype: string; @@ -22,7 +22,7 @@ export function transformStyle( const nativeStyle: { [key: string]: StyleValue } = {}; const styleProps = Object.keys(style) as (keyof typeof style)[]; for (const styleProp of styleProps) { - const styleType = getStyleType(styleProp); + const styleType = getStylePropertyType(styleProp); let rawStyle: RawValueType | undefined = style[styleProp]; if (styleType === "color" && typeof rawStyle === "string") { diff --git a/src/utils/getStylePropertyType.ts b/src/utils/getStylePropertyType.ts new file mode 100644 index 000000000..e4c8b3786 --- /dev/null +++ b/src/utils/getStylePropertyType.ts @@ -0,0 +1,265 @@ +/* eslint-disable */ +// DO NOT MODIFY +// This file is auto-generated from scripts/templates/getStylePropertyType.ts.ejs + +import { isAndroid } from "./index"; + +const StyleType = { + Constant: "constant", + Color: "color", + Transition: "transition", + Translation: "translation", + Function: "function", + Image: "image", + Enum: "enum", +}; + +const STYLE_MAP = { + fillSortKey: StyleType.Constant, + fillAntialias: StyleType.Constant, + fillOpacity: StyleType.Constant, + fillOpacityTransition: StyleType.Transition, + fillColor: StyleType.Color, + fillColorTransition: StyleType.Transition, + fillOutlineColor: StyleType.Color, + fillOutlineColorTransition: StyleType.Transition, + fillTranslate: StyleType.Translation, + fillTranslateTransition: StyleType.Transition, + fillTranslateAnchor: StyleType.Enum, + fillPattern: StyleType.Image, + fillPatternTransition: StyleType.Transition, + + lineCap: StyleType.Enum, + lineJoin: StyleType.Enum, + lineMiterLimit: StyleType.Constant, + lineRoundLimit: StyleType.Constant, + lineSortKey: StyleType.Constant, + lineOpacity: StyleType.Constant, + lineOpacityTransition: StyleType.Transition, + lineColor: StyleType.Color, + lineColorTransition: StyleType.Transition, + lineTranslate: StyleType.Translation, + lineTranslateTransition: StyleType.Transition, + lineTranslateAnchor: StyleType.Enum, + lineWidth: StyleType.Constant, + lineWidthTransition: StyleType.Transition, + lineGapWidth: StyleType.Constant, + lineGapWidthTransition: StyleType.Transition, + lineOffset: StyleType.Constant, + lineOffsetTransition: StyleType.Transition, + lineBlur: StyleType.Constant, + lineBlurTransition: StyleType.Transition, + lineDasharray: StyleType.Constant, + lineDasharrayTransition: StyleType.Transition, + linePattern: StyleType.Image, + linePatternTransition: StyleType.Transition, + lineGradient: StyleType.Color, + + symbolPlacement: StyleType.Enum, + symbolSpacing: StyleType.Constant, + symbolAvoidEdges: StyleType.Constant, + symbolSortKey: StyleType.Constant, + symbolZOrder: StyleType.Enum, + iconAllowOverlap: StyleType.Constant, + iconIgnorePlacement: StyleType.Constant, + iconOptional: StyleType.Constant, + iconRotationAlignment: StyleType.Enum, + iconSize: StyleType.Constant, + iconTextFit: StyleType.Enum, + iconTextFitPadding: StyleType.Constant, + iconImage: StyleType.Image, + iconRotate: StyleType.Constant, + iconPadding: StyleType.Constant, + iconKeepUpright: StyleType.Constant, + iconOffset: StyleType.Constant, + iconAnchor: StyleType.Enum, + iconPitchAlignment: StyleType.Enum, + textPitchAlignment: StyleType.Enum, + textRotationAlignment: StyleType.Enum, + textField: StyleType.Constant, + textFont: StyleType.Constant, + textSize: StyleType.Constant, + textMaxWidth: StyleType.Constant, + textLineHeight: StyleType.Constant, + textLetterSpacing: StyleType.Constant, + textJustify: StyleType.Enum, + textRadialOffset: StyleType.Constant, + textVariableAnchor: StyleType.Constant, + textAnchor: StyleType.Enum, + textMaxAngle: StyleType.Constant, + textWritingMode: StyleType.Constant, + textRotate: StyleType.Constant, + textPadding: StyleType.Constant, + textKeepUpright: StyleType.Constant, + textTransform: StyleType.Enum, + textOffset: StyleType.Constant, + textAllowOverlap: StyleType.Constant, + textIgnorePlacement: StyleType.Constant, + textOptional: StyleType.Constant, + iconOpacity: StyleType.Constant, + iconOpacityTransition: StyleType.Transition, + iconColor: StyleType.Color, + iconColorTransition: StyleType.Transition, + iconHaloColor: StyleType.Color, + iconHaloColorTransition: StyleType.Transition, + iconHaloWidth: StyleType.Constant, + iconHaloWidthTransition: StyleType.Transition, + iconHaloBlur: StyleType.Constant, + iconHaloBlurTransition: StyleType.Transition, + iconTranslate: StyleType.Translation, + iconTranslateTransition: StyleType.Transition, + iconTranslateAnchor: StyleType.Enum, + textOpacity: StyleType.Constant, + textOpacityTransition: StyleType.Transition, + textColor: StyleType.Color, + textColorTransition: StyleType.Transition, + textHaloColor: StyleType.Color, + textHaloColorTransition: StyleType.Transition, + textHaloWidth: StyleType.Constant, + textHaloWidthTransition: StyleType.Transition, + textHaloBlur: StyleType.Constant, + textHaloBlurTransition: StyleType.Transition, + textTranslate: StyleType.Translation, + textTranslateTransition: StyleType.Transition, + textTranslateAnchor: StyleType.Enum, + + circleSortKey: StyleType.Constant, + circleRadius: StyleType.Constant, + circleRadiusTransition: StyleType.Transition, + circleColor: StyleType.Color, + circleColorTransition: StyleType.Transition, + circleBlur: StyleType.Constant, + circleBlurTransition: StyleType.Transition, + circleOpacity: StyleType.Constant, + circleOpacityTransition: StyleType.Transition, + circleTranslate: StyleType.Translation, + circleTranslateTransition: StyleType.Transition, + circleTranslateAnchor: StyleType.Enum, + circlePitchScale: StyleType.Enum, + circlePitchAlignment: StyleType.Enum, + circleStrokeWidth: StyleType.Constant, + circleStrokeWidthTransition: StyleType.Transition, + circleStrokeColor: StyleType.Color, + circleStrokeColorTransition: StyleType.Transition, + circleStrokeOpacity: StyleType.Constant, + circleStrokeOpacityTransition: StyleType.Transition, + + heatmapRadius: StyleType.Constant, + heatmapRadiusTransition: StyleType.Transition, + heatmapWeight: StyleType.Constant, + heatmapIntensity: StyleType.Constant, + heatmapIntensityTransition: StyleType.Transition, + heatmapColor: StyleType.Color, + heatmapOpacity: StyleType.Constant, + heatmapOpacityTransition: StyleType.Transition, + + fillExtrusionOpacity: StyleType.Constant, + fillExtrusionOpacityTransition: StyleType.Transition, + fillExtrusionColor: StyleType.Color, + fillExtrusionColorTransition: StyleType.Transition, + fillExtrusionTranslate: StyleType.Translation, + fillExtrusionTranslateTransition: StyleType.Transition, + fillExtrusionTranslateAnchor: StyleType.Enum, + fillExtrusionPattern: StyleType.Image, + fillExtrusionPatternTransition: StyleType.Transition, + fillExtrusionHeight: StyleType.Constant, + fillExtrusionHeightTransition: StyleType.Transition, + fillExtrusionBase: StyleType.Constant, + fillExtrusionBaseTransition: StyleType.Transition, + fillExtrusionVerticalGradient: StyleType.Constant, + + rasterOpacity: StyleType.Constant, + rasterOpacityTransition: StyleType.Transition, + rasterHueRotate: StyleType.Constant, + rasterHueRotateTransition: StyleType.Transition, + rasterBrightnessMin: StyleType.Constant, + rasterBrightnessMinTransition: StyleType.Transition, + rasterBrightnessMax: StyleType.Constant, + rasterBrightnessMaxTransition: StyleType.Transition, + rasterSaturation: StyleType.Constant, + rasterSaturationTransition: StyleType.Transition, + rasterContrast: StyleType.Constant, + rasterContrastTransition: StyleType.Transition, + rasterResampling: StyleType.Enum, + rasterFadeDuration: StyleType.Constant, + + hillshadeIlluminationDirection: StyleType.Constant, + hillshadeIlluminationAnchor: StyleType.Enum, + hillshadeExaggeration: StyleType.Constant, + hillshadeExaggerationTransition: StyleType.Transition, + hillshadeShadowColor: StyleType.Color, + hillshadeShadowColorTransition: StyleType.Transition, + hillshadeHighlightColor: StyleType.Color, + hillshadeHighlightColorTransition: StyleType.Transition, + hillshadeAccentColor: StyleType.Color, + hillshadeAccentColorTransition: StyleType.Transition, + + backgroundColor: StyleType.Color, + backgroundColorTransition: StyleType.Transition, + backgroundPattern: StyleType.Image, + backgroundPatternTransition: StyleType.Transition, + backgroundOpacity: StyleType.Constant, + backgroundOpacityTransition: StyleType.Transition, + + anchor: StyleType.Enum, + position: StyleType.Constant, + positionTransition: StyleType.Transition, + color: StyleType.Color, + colorTransition: StyleType.Transition, + intensity: StyleType.Constant, + intensityTransition: StyleType.Transition, + + visibility: StyleType.Constant, +}; + +const STYLE_OVERRIDES = { + // padding + iconTextFitPadding: { + iosType: "edgeinsets", + }, + + // offsets + iconOffset: { + iosType: "vector", + }, + textOffset: { + iosType: "vector", + }, + lineOffset: { + iosType: "vector", + }, + + // translates + fillTranslate: { + iosType: "vector", + }, + lineTranslate: { + iosType: "vector", + }, + iconTranslate: { + iosType: "vector", + }, + textTranslate: { + iosType: "vector", + }, + circleTranslate: { + iosType: "vector", + }, + fillExtrusionTranslate: { + iosType: "vector", + }, +}; + +export function getStylePropertyType( + styleProperty: keyof typeof STYLE_OVERRIDES, +): string { + if (!isAndroid() && STYLE_OVERRIDES[styleProperty]) { + return STYLE_OVERRIDES[styleProperty].iosType; + } + + if (STYLE_MAP[styleProperty]) { + return STYLE_MAP[styleProperty]; + } + + throw new Error(`${styleProperty} is not a valid MapLibre layer style`); +} diff --git a/src/utils/styleMap.ts b/src/utils/styleMap.ts deleted file mode 100644 index dbd66dc3d..000000000 --- a/src/utils/styleMap.ts +++ /dev/null @@ -1,265 +0,0 @@ -/* eslint-disable */ -// DO NOT MODIFY -// This file is auto-generated from scripts/templates/styleMap.ts.ejs - -import { isAndroid } from "./index"; - -export const StyleTypes = { - Constant: "constant", - Color: "color", - Transition: "transition", - Translation: "translation", - Function: "function", - Image: "image", - Enum: "enum", -}; - -export function getStyleType(styleProp: keyof typeof styleExtras): string { - if (!isAndroid() && styleExtras[styleProp]) { - return styleExtras[styleProp].iosType; - } - - if (styleMap[styleProp]) { - return styleMap[styleProp]; - } - - throw new Error(`${styleProp} is not a valid MapLibre layer style`); -} - -const styleMap = { - fillSortKey: StyleTypes.Constant, - fillAntialias: StyleTypes.Constant, - fillOpacity: StyleTypes.Constant, - fillOpacityTransition: StyleTypes.Transition, - fillColor: StyleTypes.Color, - fillColorTransition: StyleTypes.Transition, - fillOutlineColor: StyleTypes.Color, - fillOutlineColorTransition: StyleTypes.Transition, - fillTranslate: StyleTypes.Translation, - fillTranslateTransition: StyleTypes.Transition, - fillTranslateAnchor: StyleTypes.Enum, - fillPattern: StyleTypes.Image, - fillPatternTransition: StyleTypes.Transition, - - lineCap: StyleTypes.Enum, - lineJoin: StyleTypes.Enum, - lineMiterLimit: StyleTypes.Constant, - lineRoundLimit: StyleTypes.Constant, - lineSortKey: StyleTypes.Constant, - lineOpacity: StyleTypes.Constant, - lineOpacityTransition: StyleTypes.Transition, - lineColor: StyleTypes.Color, - lineColorTransition: StyleTypes.Transition, - lineTranslate: StyleTypes.Translation, - lineTranslateTransition: StyleTypes.Transition, - lineTranslateAnchor: StyleTypes.Enum, - lineWidth: StyleTypes.Constant, - lineWidthTransition: StyleTypes.Transition, - lineGapWidth: StyleTypes.Constant, - lineGapWidthTransition: StyleTypes.Transition, - lineOffset: StyleTypes.Constant, - lineOffsetTransition: StyleTypes.Transition, - lineBlur: StyleTypes.Constant, - lineBlurTransition: StyleTypes.Transition, - lineDasharray: StyleTypes.Constant, - lineDasharrayTransition: StyleTypes.Transition, - linePattern: StyleTypes.Image, - linePatternTransition: StyleTypes.Transition, - lineGradient: StyleTypes.Color, - - symbolPlacement: StyleTypes.Enum, - symbolSpacing: StyleTypes.Constant, - symbolAvoidEdges: StyleTypes.Constant, - symbolSortKey: StyleTypes.Constant, - symbolZOrder: StyleTypes.Enum, - iconAllowOverlap: StyleTypes.Constant, - iconIgnorePlacement: StyleTypes.Constant, - iconOptional: StyleTypes.Constant, - iconRotationAlignment: StyleTypes.Enum, - iconSize: StyleTypes.Constant, - iconTextFit: StyleTypes.Enum, - iconTextFitPadding: StyleTypes.Constant, - iconImage: StyleTypes.Image, - iconRotate: StyleTypes.Constant, - iconPadding: StyleTypes.Constant, - iconKeepUpright: StyleTypes.Constant, - iconOffset: StyleTypes.Constant, - iconAnchor: StyleTypes.Enum, - iconPitchAlignment: StyleTypes.Enum, - textPitchAlignment: StyleTypes.Enum, - textRotationAlignment: StyleTypes.Enum, - textField: StyleTypes.Constant, - textFont: StyleTypes.Constant, - textSize: StyleTypes.Constant, - textMaxWidth: StyleTypes.Constant, - textLineHeight: StyleTypes.Constant, - textLetterSpacing: StyleTypes.Constant, - textJustify: StyleTypes.Enum, - textRadialOffset: StyleTypes.Constant, - textVariableAnchor: StyleTypes.Constant, - textAnchor: StyleTypes.Enum, - textMaxAngle: StyleTypes.Constant, - textWritingMode: StyleTypes.Constant, - textRotate: StyleTypes.Constant, - textPadding: StyleTypes.Constant, - textKeepUpright: StyleTypes.Constant, - textTransform: StyleTypes.Enum, - textOffset: StyleTypes.Constant, - textAllowOverlap: StyleTypes.Constant, - textIgnorePlacement: StyleTypes.Constant, - textOptional: StyleTypes.Constant, - iconOpacity: StyleTypes.Constant, - iconOpacityTransition: StyleTypes.Transition, - iconColor: StyleTypes.Color, - iconColorTransition: StyleTypes.Transition, - iconHaloColor: StyleTypes.Color, - iconHaloColorTransition: StyleTypes.Transition, - iconHaloWidth: StyleTypes.Constant, - iconHaloWidthTransition: StyleTypes.Transition, - iconHaloBlur: StyleTypes.Constant, - iconHaloBlurTransition: StyleTypes.Transition, - iconTranslate: StyleTypes.Translation, - iconTranslateTransition: StyleTypes.Transition, - iconTranslateAnchor: StyleTypes.Enum, - textOpacity: StyleTypes.Constant, - textOpacityTransition: StyleTypes.Transition, - textColor: StyleTypes.Color, - textColorTransition: StyleTypes.Transition, - textHaloColor: StyleTypes.Color, - textHaloColorTransition: StyleTypes.Transition, - textHaloWidth: StyleTypes.Constant, - textHaloWidthTransition: StyleTypes.Transition, - textHaloBlur: StyleTypes.Constant, - textHaloBlurTransition: StyleTypes.Transition, - textTranslate: StyleTypes.Translation, - textTranslateTransition: StyleTypes.Transition, - textTranslateAnchor: StyleTypes.Enum, - - circleSortKey: StyleTypes.Constant, - circleRadius: StyleTypes.Constant, - circleRadiusTransition: StyleTypes.Transition, - circleColor: StyleTypes.Color, - circleColorTransition: StyleTypes.Transition, - circleBlur: StyleTypes.Constant, - circleBlurTransition: StyleTypes.Transition, - circleOpacity: StyleTypes.Constant, - circleOpacityTransition: StyleTypes.Transition, - circleTranslate: StyleTypes.Translation, - circleTranslateTransition: StyleTypes.Transition, - circleTranslateAnchor: StyleTypes.Enum, - circlePitchScale: StyleTypes.Enum, - circlePitchAlignment: StyleTypes.Enum, - circleStrokeWidth: StyleTypes.Constant, - circleStrokeWidthTransition: StyleTypes.Transition, - circleStrokeColor: StyleTypes.Color, - circleStrokeColorTransition: StyleTypes.Transition, - circleStrokeOpacity: StyleTypes.Constant, - circleStrokeOpacityTransition: StyleTypes.Transition, - - heatmapRadius: StyleTypes.Constant, - heatmapRadiusTransition: StyleTypes.Transition, - heatmapWeight: StyleTypes.Constant, - heatmapIntensity: StyleTypes.Constant, - heatmapIntensityTransition: StyleTypes.Transition, - heatmapColor: StyleTypes.Color, - heatmapOpacity: StyleTypes.Constant, - heatmapOpacityTransition: StyleTypes.Transition, - - fillExtrusionOpacity: StyleTypes.Constant, - fillExtrusionOpacityTransition: StyleTypes.Transition, - fillExtrusionColor: StyleTypes.Color, - fillExtrusionColorTransition: StyleTypes.Transition, - fillExtrusionTranslate: StyleTypes.Translation, - fillExtrusionTranslateTransition: StyleTypes.Transition, - fillExtrusionTranslateAnchor: StyleTypes.Enum, - fillExtrusionPattern: StyleTypes.Image, - fillExtrusionPatternTransition: StyleTypes.Transition, - fillExtrusionHeight: StyleTypes.Constant, - fillExtrusionHeightTransition: StyleTypes.Transition, - fillExtrusionBase: StyleTypes.Constant, - fillExtrusionBaseTransition: StyleTypes.Transition, - fillExtrusionVerticalGradient: StyleTypes.Constant, - - rasterOpacity: StyleTypes.Constant, - rasterOpacityTransition: StyleTypes.Transition, - rasterHueRotate: StyleTypes.Constant, - rasterHueRotateTransition: StyleTypes.Transition, - rasterBrightnessMin: StyleTypes.Constant, - rasterBrightnessMinTransition: StyleTypes.Transition, - rasterBrightnessMax: StyleTypes.Constant, - rasterBrightnessMaxTransition: StyleTypes.Transition, - rasterSaturation: StyleTypes.Constant, - rasterSaturationTransition: StyleTypes.Transition, - rasterContrast: StyleTypes.Constant, - rasterContrastTransition: StyleTypes.Transition, - rasterResampling: StyleTypes.Enum, - rasterFadeDuration: StyleTypes.Constant, - - hillshadeIlluminationDirection: StyleTypes.Constant, - hillshadeIlluminationAnchor: StyleTypes.Enum, - hillshadeExaggeration: StyleTypes.Constant, - hillshadeExaggerationTransition: StyleTypes.Transition, - hillshadeShadowColor: StyleTypes.Color, - hillshadeShadowColorTransition: StyleTypes.Transition, - hillshadeHighlightColor: StyleTypes.Color, - hillshadeHighlightColorTransition: StyleTypes.Transition, - hillshadeAccentColor: StyleTypes.Color, - hillshadeAccentColorTransition: StyleTypes.Transition, - - backgroundColor: StyleTypes.Color, - backgroundColorTransition: StyleTypes.Transition, - backgroundPattern: StyleTypes.Image, - backgroundPatternTransition: StyleTypes.Transition, - backgroundOpacity: StyleTypes.Constant, - backgroundOpacityTransition: StyleTypes.Transition, - - anchor: StyleTypes.Enum, - position: StyleTypes.Constant, - positionTransition: StyleTypes.Transition, - color: StyleTypes.Color, - colorTransition: StyleTypes.Transition, - intensity: StyleTypes.Constant, - intensityTransition: StyleTypes.Transition, - - visibility: StyleTypes.Constant, -}; - -export const styleExtras = { - // padding - iconTextFitPadding: { - iosType: "edgeinsets", - }, - - // offsets - iconOffset: { - iosType: "vector", - }, - textOffset: { - iosType: "vector", - }, - lineOffset: { - iosType: "vector", - }, - - // translates - fillTranslate: { - iosType: "vector", - }, - lineTranslate: { - iosType: "vector", - }, - iconTranslate: { - iosType: "vector", - }, - textTranslate: { - iosType: "vector", - }, - circleTranslate: { - iosType: "vector", - }, - fillExtrusionTranslate: { - iosType: "vector", - }, -}; - -export default styleMap; From c5e946bb2766f74f9096444416044919791ef7df Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 15:34:09 +0100 Subject: [PATCH 7/9] refactor: drop Props suffix on style types --- docs/components/BackgroundLayer.md | 2 +- docs/components/CircleLayer.md | 2 +- docs/components/FillExtrusionLayer.md | 2 +- docs/components/FillLayer.md | 2 +- docs/components/HeatmapLayer.md | 2 +- docs/components/Light.md | 2 +- docs/components/LineLayer.md | 2 +- docs/components/RasterLayer.md | 2 +- docs/components/SymbolLayer.md | 2 +- docs/docs.json | 18 +++++----- scripts/templates/MapLibreRNStyles.ts.ejs | 4 +-- src/MapLibreRN.ts | 20 +++++------ src/components/Annotation.tsx | 6 ++-- src/components/BackgroundLayer.tsx | 4 +-- src/components/CircleLayer.tsx | 4 +-- src/components/FillExtrusionLayer.tsx | 4 +-- src/components/FillLayer.tsx | 4 +-- src/components/HeatmapLayer.tsx | 4 +-- src/components/Light.tsx | 4 +-- src/components/LineLayer.tsx | 4 +-- src/components/RasterLayer.tsx | 4 +-- src/components/SymbolLayer.tsx | 4 +-- src/components/UserLocation.tsx | 4 +-- src/hooks/useAbstractLayer.ts | 4 +-- src/utils/MapLibreRNStyles.d.ts | 42 +++++++++++------------ src/utils/StyleValue.ts | 4 +-- 26 files changed, 78 insertions(+), 78 deletions(-) diff --git a/docs/components/BackgroundLayer.md b/docs/components/BackgroundLayer.md index d532ed197..125505713 100644 --- a/docs/components/BackgroundLayer.md +++ b/docs/components/BackgroundLayer.md @@ -6,7 +6,7 @@ ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `BackgroundLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `BackgroundLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/CircleLayer.md b/docs/components/CircleLayer.md index de5fbaae3..c9e90fdea 100644 --- a/docs/components/CircleLayer.md +++ b/docs/components/CircleLayer.md @@ -6,7 +6,7 @@ CircleLayer is a style layer that renders one or more filled circles on the map. ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `CircleLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `CircleLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/FillExtrusionLayer.md b/docs/components/FillExtrusionLayer.md index 89ff80e32..f5ef3dc1f 100644 --- a/docs/components/FillExtrusionLayer.md +++ b/docs/components/FillExtrusionLayer.md @@ -6,7 +6,7 @@ FillExtrusionLayer is a style layer that renders one or more 3D extruded polygon ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `FillExtrusionLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `FillExtrusionLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/FillLayer.md b/docs/components/FillLayer.md index 797b51373..ee990dc72 100644 --- a/docs/components/FillLayer.md +++ b/docs/components/FillLayer.md @@ -6,7 +6,7 @@ FillLayer is a style layer that renders one or more filled (and optionally strok ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `FillLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `FillLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/HeatmapLayer.md b/docs/components/HeatmapLayer.md index 0a54971c4..307472972 100644 --- a/docs/components/HeatmapLayer.md +++ b/docs/components/HeatmapLayer.md @@ -6,7 +6,7 @@ HeatmapLayer is a style layer that renders one or more filled circles on the map ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `HeatmapLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `HeatmapLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/Light.md b/docs/components/Light.md index e78d3ed5a..d17997119 100644 --- a/docs/components/Light.md +++ b/docs/components/Light.md @@ -6,7 +6,7 @@ Light represents the light source for extruded geometries ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `LightLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `LightLayerStyle` | `none` | `false` | Customizable style attributes | ## Styles diff --git a/docs/components/LineLayer.md b/docs/components/LineLayer.md index e1d1d2720..55dd18304 100644 --- a/docs/components/LineLayer.md +++ b/docs/components/LineLayer.md @@ -6,7 +6,7 @@ LineLayer is a style layer that renders one or more stroked polylines on the map ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `LineLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `LineLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/RasterLayer.md b/docs/components/RasterLayer.md index 0eb561ca4..1ff8a4f10 100644 --- a/docs/components/RasterLayer.md +++ b/docs/components/RasterLayer.md @@ -6,7 +6,7 @@ ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `RasterLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `RasterLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/components/SymbolLayer.md b/docs/components/SymbolLayer.md index 0fcdc20db..673037285 100644 --- a/docs/components/SymbolLayer.md +++ b/docs/components/SymbolLayer.md @@ -6,7 +6,7 @@ SymbolLayer is a style layer that renders icon and text labels at points or alon ## Props | Prop | Type | Default | Required | Description | | ---- | :--: | :-----: | :------: | :----------: | -| style | `SymbolLayerStyleProps` | `none` | `false` | Customizable style attributes | +| style | `SymbolLayerStyle` | `none` | `false` | Customizable style attributes | | sourceID | `FIX ME UNKNOWN TYPE` | `MapLibreRN.StyleSource.DefaultSourceID` | `false` | FIX ME NO DESCRIPTION | diff --git a/docs/docs.json b/docs/docs.json index 49dd675b4..cfcb91f01 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -93,7 +93,7 @@ { "name": "style", "required": false, - "type": "BackgroundLayerStyleProps", + "type": "BackgroundLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -562,7 +562,7 @@ { "name": "style", "required": false, - "type": "CircleLayerStyleProps", + "type": "CircleLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -866,7 +866,7 @@ { "name": "style", "required": false, - "type": "FillExtrusionLayerStyleProps", + "type": "FillExtrusionLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -1081,7 +1081,7 @@ { "name": "style", "required": false, - "type": "FillLayerStyleProps", + "type": "FillLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -1309,7 +1309,7 @@ { "name": "style", "required": false, - "type": "HeatmapLayerStyleProps", + "type": "HeatmapLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -1568,7 +1568,7 @@ { "name": "style", "required": false, - "type": "LightLayerStyleProps", + "type": "LightLayerStyle", "default": "none", "description": "Customizable style attributes" } @@ -1674,7 +1674,7 @@ { "name": "style", "required": false, - "type": "LineLayerStyleProps", + "type": "LineLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -2772,7 +2772,7 @@ { "name": "style", "required": false, - "type": "RasterLayerStyleProps", + "type": "RasterLayerStyle", "default": "none", "description": "Customizable style attributes" }, @@ -3363,7 +3363,7 @@ { "name": "style", "required": false, - "type": "SymbolLayerStyleProps", + "type": "SymbolLayerStyle", "default": "none", "description": "Customizable style attributes" }, diff --git a/scripts/templates/MapLibreRNStyles.ts.ejs b/scripts/templates/MapLibreRNStyles.ts.ejs index a78c9d91f..a5a5021c9 100644 --- a/scripts/templates/MapLibreRNStyles.ts.ejs +++ b/scripts/templates/MapLibreRNStyles.ts.ejs @@ -62,7 +62,7 @@ export type Value = | Expression; <%_ for (let layer of layers) { _%> - export interface <%- helpers.pascalCase(layer.name) %>LayerStyleProps { + export interface <%- helpers.pascalCase(layer.name) %>LayerStyle { <%_ for (let prop of layer.properties) { _%> /** * <%- prop.doc.description %> @@ -87,4 +87,4 @@ export type Value = }; <%_ } _%> -export type AllLayerStyleProps = <%- layers.map(l => `${helpers.pascalCase(l.name)}LayerStyleProps`).join("|") -%>; \ No newline at end of file +export type AllLayerStyle = <%- layers.map(l => `${helpers.pascalCase(l.name)}LayerStyle`).join("|") -%>; \ No newline at end of file diff --git a/src/MapLibreRN.ts b/src/MapLibreRN.ts index 9886dcd38..3135c7212 100644 --- a/src/MapLibreRN.ts +++ b/src/MapLibreRN.ts @@ -56,14 +56,14 @@ export type { MapLibreRNEvent } from "./types/MapLibreRNEvent"; export { default as Animated } from "./utils/animated/Animated"; export { default as Logger, type LogLevel } from "./utils/Logger"; export type { - FillLayerStyleProps as FillLayerStyle, - LineLayerStyleProps as LineLayerStyle, - SymbolLayerStyleProps as SymbolLayerStyle, - CircleLayerStyleProps as CircleLayerStyle, - HeatmapLayerStyleProps as HeatmapLayerStyle, - FillExtrusionLayerStyleProps as FillExtrusionLayerStyle, - RasterLayerStyleProps as RasterLayerStyle, - HillshadeLayerStyleProps as HillshadeLayerStyle, - BackgroundLayerStyleProps as BackgroundLayerStyle, - LightLayerStyleProps as LightLayerStyle, + FillLayerStyle, + LineLayerStyle, + SymbolLayerStyle, + CircleLayerStyle, + HeatmapLayerStyle, + FillExtrusionLayerStyle, + RasterLayerStyle, + HillshadeLayerStyle, + BackgroundLayerStyle, + LightLayerStyle, } from "./utils/MapLibreRNStyles"; diff --git a/src/components/Annotation.tsx b/src/components/Annotation.tsx index 6c8ec6811..9ed478466 100644 --- a/src/components/Annotation.tsx +++ b/src/components/Annotation.tsx @@ -10,7 +10,7 @@ import { Animated as RNAnimated, Easing } from "react-native"; import SymbolLayer from "./SymbolLayer"; import { type OnPressEvent } from "../types/OnPressEvent"; -import { type SymbolLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type SymbolLayerStyle } from "../utils/MapLibreRNStyles"; import { AnimatedShapeSource } from "../utils/animated/Animated"; import AnimatedMapPoint from "../utils/animated/AnimatedPoint"; @@ -46,7 +46,7 @@ function isShapeAnimated(shape: Shape): shape is AnimatedMapPoint { interface AnnotationRef { onPress(event: OnPressEvent): void; - symbolStyle: SymbolLayerStyleProps | undefined; + symbolStyle: SymbolLayerStyle | undefined; } const Annotation = forwardRef( @@ -126,7 +126,7 @@ const Annotation = forwardRef( } const children = []; - const symbolStyle: SymbolLayerStyleProps | undefined = props.icon + const symbolStyle: SymbolLayerStyle | undefined = props.icon ? { ...props.style, iconImage: typeof props.icon === "string" ? props.icon : undefined, diff --git a/src/components/BackgroundLayer.tsx b/src/components/BackgroundLayer.tsx index 9304768b0..af586c3ad 100644 --- a/src/components/BackgroundLayer.tsx +++ b/src/components/BackgroundLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type BackgroundLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type BackgroundLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface BackgroundLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: BackgroundLayerStyleProps; + style?: BackgroundLayerStyle; } interface NativeProps diff --git a/src/components/CircleLayer.tsx b/src/components/CircleLayer.tsx index b4b7274d8..3497fa698 100644 --- a/src/components/CircleLayer.tsx +++ b/src/components/CircleLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type CircleLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type CircleLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface CircleLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: CircleLayerStyleProps; + style?: CircleLayerStyle; } interface NativeProps diff --git a/src/components/FillExtrusionLayer.tsx b/src/components/FillExtrusionLayer.tsx index 9133a4bbc..003962cb6 100644 --- a/src/components/FillExtrusionLayer.tsx +++ b/src/components/FillExtrusionLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type FillExtrusionLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type FillExtrusionLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface FillExtrusionLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: FillExtrusionLayerStyleProps; + style?: FillExtrusionLayerStyle; } interface NativeProps diff --git a/src/components/FillLayer.tsx b/src/components/FillLayer.tsx index e54a393c9..5944b80c8 100644 --- a/src/components/FillLayer.tsx +++ b/src/components/FillLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type FillLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type FillLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface FillLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: FillLayerStyleProps; + style?: FillLayerStyle; } interface NativeProps extends Omit, NativeBaseProps {} diff --git a/src/components/HeatmapLayer.tsx b/src/components/HeatmapLayer.tsx index 9be2d8cac..eb728469b 100644 --- a/src/components/HeatmapLayer.tsx +++ b/src/components/HeatmapLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type HeatmapLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type HeatmapLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface HeatmapLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: HeatmapLayerStyleProps; + style?: HeatmapLayerStyle; } interface NativeProps diff --git a/src/components/Light.tsx b/src/components/Light.tsx index eec816bd5..0cf125d37 100644 --- a/src/components/Light.tsx +++ b/src/components/Light.tsx @@ -5,7 +5,7 @@ import useAbstractLayer, { type BaseLayerProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type LightLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type LightLayerStyle } from "../utils/MapLibreRNStyles"; import { type StyleValue } from "../utils/StyleValue"; export const NATIVE_MODULE_NAME = "MLRNLight"; @@ -14,7 +14,7 @@ interface LightProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: LightLayerStyleProps; + style?: LightLayerStyle; } interface NativeProps extends Omit { diff --git a/src/components/LineLayer.tsx b/src/components/LineLayer.tsx index 908aea6f8..a8b3d31f6 100644 --- a/src/components/LineLayer.tsx +++ b/src/components/LineLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type LineLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type LineLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface LineLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: LineLayerStyleProps; + style?: LineLayerStyle; } interface NativeProps extends Omit, NativeBaseProps {} diff --git a/src/components/RasterLayer.tsx b/src/components/RasterLayer.tsx index bfded88c1..ccad105de 100644 --- a/src/components/RasterLayer.tsx +++ b/src/components/RasterLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type RasterLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type RasterLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -16,7 +16,7 @@ export interface RasterLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: RasterLayerStyleProps; + style?: RasterLayerStyle; } interface NativeProps diff --git a/src/components/SymbolLayer.tsx b/src/components/SymbolLayer.tsx index 41a3d291d..cd2f55062 100644 --- a/src/components/SymbolLayer.tsx +++ b/src/components/SymbolLayer.tsx @@ -5,7 +5,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type SymbolLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type SymbolLayerStyle } from "../utils/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; @@ -15,7 +15,7 @@ export interface SymbolLayerProps extends BaseProps, BaseLayerProps { /** * Customizable style attributes */ - style?: SymbolLayerStyleProps; + style?: SymbolLayerStyle; } interface NativeProps diff --git a/src/components/UserLocation.tsx b/src/components/UserLocation.tsx index e5ded6551..4ffdf603a 100644 --- a/src/components/UserLocation.tsx +++ b/src/components/UserLocation.tsx @@ -15,11 +15,11 @@ import NativeUserLocation from "./NativeUserLocation"; import locationManager, { type Location, } from "../modules/location/locationManager"; -import { type CircleLayerStyleProps } from "../utils/MapLibreRNStyles"; +import { type CircleLayerStyle } from "../utils/MapLibreRNStyles"; const mapboxBlue = "rgba(51, 181, 229, 100)"; -const layerStyles: Record = { +const layerStyles: Record = { pluse: { circleRadius: 15, circleColor: mapboxBlue, diff --git a/src/hooks/useAbstractLayer.ts b/src/hooks/useAbstractLayer.ts index 5e9aeef5f..e59391c8a 100644 --- a/src/hooks/useAbstractLayer.ts +++ b/src/hooks/useAbstractLayer.ts @@ -3,7 +3,7 @@ import { processColor, type NativeMethods } from "react-native"; import { type BaseProps } from "../types/BaseProps"; import { - type AllLayerStyleProps, + type AllLayerStyle, type ExpressionField, type ExpressionName, type FilterExpression, @@ -53,7 +53,7 @@ export interface BaseLayerProps { /** * Customizable style attributes */ - style?: AllLayerStyleProps; + style?: AllLayerStyle; } export interface NativeBaseProps { diff --git a/src/utils/MapLibreRNStyles.d.ts b/src/utils/MapLibreRNStyles.d.ts index 61d37f413..ca3c6d3b8 100644 --- a/src/utils/MapLibreRNStyles.d.ts +++ b/src/utils/MapLibreRNStyles.d.ts @@ -134,7 +134,7 @@ export type Value = | T | Expression; -export interface FillLayerStyleProps { +export interface FillLayerStyle { /** * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. */ @@ -203,7 +203,7 @@ export interface FillLayerStyleProps { */ fillPatternTransition?: Transition; } -export interface LineLayerStyleProps { +export interface LineLayerStyle { /** * The display of line endings. */ @@ -326,7 +326,7 @@ export interface LineLayerStyleProps { */ lineGradient?: Value; } -export interface SymbolLayerStyleProps { +export interface SymbolLayerStyle { /** * Label placement relative to its geometry. */ @@ -762,7 +762,7 @@ The unit is in pixels only for SDF sprites that were created with a blur radius */ textTranslateAnchor?: Value<"map" | "viewport", ["zoom"]>; } -export interface CircleLayerStyleProps { +export interface CircleLayerStyle { /** * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. */ @@ -858,7 +858,7 @@ export interface CircleLayerStyleProps { */ circleStrokeOpacityTransition?: Transition; } -export interface HeatmapLayerStyleProps { +export interface HeatmapLayerStyle { /** * Whether this layer is displayed. */ @@ -899,7 +899,7 @@ export interface HeatmapLayerStyleProps { */ heatmapOpacityTransition?: Transition; } -export interface FillExtrusionLayerStyleProps { +export interface FillExtrusionLayerStyle { /** * Whether this layer is displayed. */ @@ -973,7 +973,7 @@ export interface FillExtrusionLayerStyleProps { */ fillExtrusionVerticalGradient?: Value; } -export interface RasterLayerStyleProps { +export interface RasterLayerStyle { /** * Whether this layer is displayed. */ @@ -1041,7 +1041,7 @@ export interface RasterLayerStyleProps { */ rasterFadeDuration?: Value; } -export interface HillshadeLayerStyleProps { +export interface HillshadeLayerStyle { /** * Whether this layer is displayed. */ @@ -1091,7 +1091,7 @@ export interface HillshadeLayerStyleProps { */ hillshadeAccentColorTransition?: Transition; } -export interface BackgroundLayerStyleProps { +export interface BackgroundLayerStyle { /** * Whether this layer is displayed. */ @@ -1126,7 +1126,7 @@ export interface BackgroundLayerStyleProps { */ backgroundOpacityTransition?: Transition; } -export interface LightLayerStyleProps { +export interface LightLayerStyle { /** * Whether extruded geometries are lit relative to the map or viewport. */ @@ -1160,14 +1160,14 @@ export interface LightLayerStyleProps { intensityTransition?: Transition; } -export type AllLayerStyleProps = - | FillLayerStyleProps - | LineLayerStyleProps - | SymbolLayerStyleProps - | CircleLayerStyleProps - | HeatmapLayerStyleProps - | FillExtrusionLayerStyleProps - | RasterLayerStyleProps - | HillshadeLayerStyleProps - | BackgroundLayerStyleProps - | LightLayerStyleProps; +export type AllLayerStyle = + | FillLayerStyle + | LineLayerStyle + | SymbolLayerStyle + | CircleLayerStyle + | HeatmapLayerStyle + | FillExtrusionLayerStyle + | RasterLayerStyle + | HillshadeLayerStyle + | BackgroundLayerStyle + | LightLayerStyle; diff --git a/src/utils/StyleValue.ts b/src/utils/StyleValue.ts index aafd05386..73cf4cf82 100644 --- a/src/utils/StyleValue.ts +++ b/src/utils/StyleValue.ts @@ -4,7 +4,7 @@ import BridgeValue, { type RawValueType, type StyleValueJSON, } from "./BridgeValue"; -import { type AllLayerStyleProps } from "./MapLibreRNStyles"; +import { type AllLayerStyle } from "./MapLibreRNStyles"; import { getStylePropertyType } from "./getStylePropertyType"; export type StyleValue = { @@ -13,7 +13,7 @@ export type StyleValue = { }; export function transformStyle( - style: AllLayerStyleProps | undefined, + style: AllLayerStyle | undefined, ): undefined | { [key: string]: StyleValue } { if (!style) { return undefined; From be6d7656abe39d3783f7236f1bbb1ec66f2b223d Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 15:55:14 +0100 Subject: [PATCH 8/9] refactor: move MapLibreRNStyles --- scripts/codegen.ts | 8 ++++---- ...{MapLibreRNStyles.ts.ejs => MapLibreRNStyles.d.ts.ejs} | 4 ++-- src/MapLibreRN.ts | 2 +- src/components/Annotation.tsx | 2 +- src/components/BackgroundLayer.tsx | 2 +- src/components/CircleLayer.tsx | 2 +- src/components/FillExtrusionLayer.tsx | 2 +- src/components/FillLayer.tsx | 2 +- src/components/HeatmapLayer.tsx | 2 +- src/components/Light.tsx | 2 +- src/components/LineLayer.tsx | 2 +- src/components/MapView.tsx | 2 +- src/components/RasterLayer.tsx | 2 +- src/components/ShapeSource.tsx | 8 ++++---- src/components/SymbolLayer.tsx | 2 +- src/components/UserLocation.tsx | 2 +- src/components/VectorSource.tsx | 2 +- src/hooks/useAbstractLayer.ts | 2 +- src/{utils => types}/MapLibreRNStyles.d.ts | 6 +++--- src/utils/StyleValue.ts | 2 +- src/utils/filterUtils.ts | 2 +- 21 files changed, 30 insertions(+), 30 deletions(-) rename scripts/templates/{MapLibreRNStyles.ts.ejs => MapLibreRNStyles.d.ts.ejs} (98%) rename src/{utils => types}/MapLibreRNStyles.d.ts (99%) diff --git a/scripts/codegen.ts b/scripts/codegen.ts index 581602a37..6c160d01b 100644 --- a/scripts/codegen.ts +++ b/scripts/codegen.ts @@ -32,7 +32,7 @@ const ANDROID_OUTPUT_PATH = path.join( "styles", ); -const JS_OUTPUT_PATH = path.join(__dirname, "..", "src", "utils"); +const JS_OUTPUT_PATH = path.join(__dirname, "..", "src"); const TEMPLATE_MAPPINGS = [ { @@ -40,8 +40,8 @@ const TEMPLATE_MAPPINGS = [ output: path.join(IOS_OUTPUT_PATH, "MLRNStyle.h"), }, { - input: path.join(TEMPLATES_PATH, "MapLibreRNStyles.ts.ejs"), - output: path.join(JS_OUTPUT_PATH, "MapLibreRNStyles.d.ts"), + input: path.join(TEMPLATES_PATH, "MapLibreRNStyles.d.ts.ejs"), + output: path.join(JS_OUTPUT_PATH, "types", "MapLibreRNStyles.d.ts"), }, { input: path.join(TEMPLATES_PATH, "MLRNStyle.m.ejs"), @@ -53,7 +53,7 @@ const TEMPLATE_MAPPINGS = [ }, { input: path.join(TEMPLATES_PATH, "getStylePropertyType.ts.ejs"), - output: path.join(JS_OUTPUT_PATH, "getStylePropertyType.ts"), + output: path.join(JS_OUTPUT_PATH, "utils", "getStylePropertyType.ts"), }, ]; diff --git a/scripts/templates/MapLibreRNStyles.ts.ejs b/scripts/templates/MapLibreRNStyles.d.ts.ejs similarity index 98% rename from scripts/templates/MapLibreRNStyles.ts.ejs rename to scripts/templates/MapLibreRNStyles.d.ts.ejs index a5a5021c9..7892eeadb 100644 --- a/scripts/templates/MapLibreRNStyles.ts.ejs +++ b/scripts/templates/MapLibreRNStyles.d.ts.ejs @@ -16,7 +16,7 @@ export interface Transition { export type FormattedString = string; /* TODO */ -type ExpressionName = +export type ExpressionName = // Types | 'array' | 'boolean' | 'collator' | 'format' | 'image' | 'literal' | 'number' | 'number-format' | 'object' | 'string' | 'to-boolean' | 'to-color' | 'to-number' | 'to-string' | 'typeof' @@ -40,7 +40,7 @@ type ExpressionName = // Zoom, Heatmap | 'zoom' | 'heatmap-density'; -type ExpressionField = +export type ExpressionField = | string | number | boolean diff --git a/src/MapLibreRN.ts b/src/MapLibreRN.ts index 3135c7212..424222148 100644 --- a/src/MapLibreRN.ts +++ b/src/MapLibreRN.ts @@ -66,4 +66,4 @@ export type { HillshadeLayerStyle, BackgroundLayerStyle, LightLayerStyle, -} from "./utils/MapLibreRNStyles"; +} from "./types/MapLibreRNStyles"; diff --git a/src/components/Annotation.tsx b/src/components/Annotation.tsx index 9ed478466..6b93fab76 100644 --- a/src/components/Annotation.tsx +++ b/src/components/Annotation.tsx @@ -9,8 +9,8 @@ import { import { Animated as RNAnimated, Easing } from "react-native"; import SymbolLayer from "./SymbolLayer"; +import { type SymbolLayerStyle } from "../types/MapLibreRNStyles"; import { type OnPressEvent } from "../types/OnPressEvent"; -import { type SymbolLayerStyle } from "../utils/MapLibreRNStyles"; import { AnimatedShapeSource } from "../utils/animated/Animated"; import AnimatedMapPoint from "../utils/animated/AnimatedPoint"; diff --git a/src/components/BackgroundLayer.tsx b/src/components/BackgroundLayer.tsx index af586c3ad..fc54d7570 100644 --- a/src/components/BackgroundLayer.tsx +++ b/src/components/BackgroundLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type BackgroundLayerStyle } from "../utils/MapLibreRNStyles"; +import { type BackgroundLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/CircleLayer.tsx b/src/components/CircleLayer.tsx index 3497fa698..50b4253a2 100644 --- a/src/components/CircleLayer.tsx +++ b/src/components/CircleLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type CircleLayerStyle } from "../utils/MapLibreRNStyles"; +import { type CircleLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/FillExtrusionLayer.tsx b/src/components/FillExtrusionLayer.tsx index 003962cb6..6ed0bc6a7 100644 --- a/src/components/FillExtrusionLayer.tsx +++ b/src/components/FillExtrusionLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type FillExtrusionLayerStyle } from "../utils/MapLibreRNStyles"; +import { type FillExtrusionLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/FillLayer.tsx b/src/components/FillLayer.tsx index 5944b80c8..aa5dd181f 100644 --- a/src/components/FillLayer.tsx +++ b/src/components/FillLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type FillLayerStyle } from "../utils/MapLibreRNStyles"; +import { type FillLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/HeatmapLayer.tsx b/src/components/HeatmapLayer.tsx index eb728469b..f4bd84bf3 100644 --- a/src/components/HeatmapLayer.tsx +++ b/src/components/HeatmapLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type HeatmapLayerStyle } from "../utils/MapLibreRNStyles"; +import { type HeatmapLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/Light.tsx b/src/components/Light.tsx index 0cf125d37..a24f2cb8e 100644 --- a/src/components/Light.tsx +++ b/src/components/Light.tsx @@ -5,7 +5,7 @@ import useAbstractLayer, { type BaseLayerProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type LightLayerStyle } from "../utils/MapLibreRNStyles"; +import { type LightLayerStyle } from "../types/MapLibreRNStyles"; import { type StyleValue } from "../utils/StyleValue"; export const NATIVE_MODULE_NAME = "MLRNLight"; diff --git a/src/components/LineLayer.tsx b/src/components/LineLayer.tsx index a8b3d31f6..1b8daa71b 100644 --- a/src/components/LineLayer.tsx +++ b/src/components/LineLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type LineLayerStyle } from "../utils/MapLibreRNStyles"; +import { type LineLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/MapView.tsx b/src/components/MapView.tsx index 97c2d6b87..ece9160a6 100644 --- a/src/components/MapView.tsx +++ b/src/components/MapView.tsx @@ -26,9 +26,9 @@ import useNativeBridge from "../hooks/useNativeBridge"; import useOnce from "../hooks/useOnce"; import { type Location } from "../modules/location/locationManager"; import { type BaseProps } from "../types/BaseProps"; +import { type FilterExpression } from "../types/MapLibreRNStyles"; import { isFunction, isAndroid } from "../utils"; import Logger from "../utils/Logger"; -import { type FilterExpression } from "../utils/MapLibreRNStyles"; import { getFilter } from "../utils/filterUtils"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/RasterLayer.tsx b/src/components/RasterLayer.tsx index ccad105de..2a0516f6b 100644 --- a/src/components/RasterLayer.tsx +++ b/src/components/RasterLayer.tsx @@ -6,7 +6,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type RasterLayerStyle } from "../utils/MapLibreRNStyles"; +import { type RasterLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/ShapeSource.tsx b/src/components/ShapeSource.tsx index 147256cfc..656b1804f 100644 --- a/src/components/ShapeSource.tsx +++ b/src/components/ShapeSource.tsx @@ -15,6 +15,10 @@ import { import useNativeBridge from "../hooks/useNativeBridge"; import { type BaseProps } from "../types/BaseProps"; +import { + type ExpressionField, + type FilterExpression, +} from "../types/MapLibreRNStyles"; import { type OnPressEvent } from "../types/OnPressEvent"; import { cloneReactChildrenWithProps, @@ -22,10 +26,6 @@ import { isFunction, toJSONString, } from "../utils"; -import { - type ExpressionField, - type FilterExpression, -} from "../utils/MapLibreRNStyles"; import { getFilter } from "../utils/filterUtils"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/SymbolLayer.tsx b/src/components/SymbolLayer.tsx index cd2f55062..18ee78526 100644 --- a/src/components/SymbolLayer.tsx +++ b/src/components/SymbolLayer.tsx @@ -5,7 +5,7 @@ import useAbstractLayer, { type NativeBaseProps, } from "../hooks/useAbstractLayer"; import { type BaseProps } from "../types/BaseProps"; -import { type SymbolLayerStyle } from "../utils/MapLibreRNStyles"; +import { type SymbolLayerStyle } from "../types/MapLibreRNStyles"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/components/UserLocation.tsx b/src/components/UserLocation.tsx index 4ffdf603a..5df37befb 100644 --- a/src/components/UserLocation.tsx +++ b/src/components/UserLocation.tsx @@ -15,7 +15,7 @@ import NativeUserLocation from "./NativeUserLocation"; import locationManager, { type Location, } from "../modules/location/locationManager"; -import { type CircleLayerStyle } from "../utils/MapLibreRNStyles"; +import { type CircleLayerStyle } from "../types/MapLibreRNStyles"; const mapboxBlue = "rgba(51, 181, 229, 100)"; diff --git a/src/components/VectorSource.tsx b/src/components/VectorSource.tsx index 604b30d9b..9c196d890 100644 --- a/src/components/VectorSource.tsx +++ b/src/components/VectorSource.tsx @@ -9,9 +9,9 @@ import { import useAbstractSource from "../hooks/useAbstractSource"; import useNativeBridge from "../hooks/useNativeBridge"; import { type BaseProps } from "../types/BaseProps"; +import { type FilterExpression } from "../types/MapLibreRNStyles"; import { type OnPressEvent } from "../types/OnPressEvent"; import { cloneReactChildrenWithProps, isFunction, isAndroid } from "../utils"; -import { type FilterExpression } from "../utils/MapLibreRNStyles"; import { getFilter } from "../utils/filterUtils"; const MapLibreRN = NativeModules.MLRNModule; diff --git a/src/hooks/useAbstractLayer.ts b/src/hooks/useAbstractLayer.ts index e59391c8a..a1079c837 100644 --- a/src/hooks/useAbstractLayer.ts +++ b/src/hooks/useAbstractLayer.ts @@ -7,7 +7,7 @@ import { type ExpressionField, type ExpressionName, type FilterExpression, -} from "../utils/MapLibreRNStyles"; +} from "../types/MapLibreRNStyles"; import { type StyleValue, transformStyle } from "../utils/StyleValue"; import { getFilter } from "../utils/filterUtils"; diff --git a/src/utils/MapLibreRNStyles.d.ts b/src/types/MapLibreRNStyles.d.ts similarity index 99% rename from src/utils/MapLibreRNStyles.d.ts rename to src/types/MapLibreRNStyles.d.ts index ca3c6d3b8..2fd501792 100644 --- a/src/utils/MapLibreRNStyles.d.ts +++ b/src/types/MapLibreRNStyles.d.ts @@ -1,5 +1,5 @@ // DO NOT MODIFY -// This file is auto-generated from scripts/templates/MapLibreRNStyles.ts.ejs +// This file is auto-generated from scripts/templates/MapLibreRNStyles.d.ts.ejs import { type ImageSourcePropType } from "react-native"; @@ -12,7 +12,7 @@ export interface Transition { export type FormattedString = string; /* TODO */ -type ExpressionName = +export type ExpressionName = // Types | "array" | "boolean" @@ -107,7 +107,7 @@ type ExpressionName = | "zoom" | "heatmap-density"; -type ExpressionField = +export type ExpressionField = | string | number | boolean diff --git a/src/utils/StyleValue.ts b/src/utils/StyleValue.ts index 73cf4cf82..efa6a0353 100644 --- a/src/utils/StyleValue.ts +++ b/src/utils/StyleValue.ts @@ -4,8 +4,8 @@ import BridgeValue, { type RawValueType, type StyleValueJSON, } from "./BridgeValue"; -import { type AllLayerStyle } from "./MapLibreRNStyles"; import { getStylePropertyType } from "./getStylePropertyType"; +import { type AllLayerStyle } from "../types/MapLibreRNStyles"; export type StyleValue = { styletype: string; diff --git a/src/utils/filterUtils.ts b/src/utils/filterUtils.ts index 39ffd8a63..7dddac161 100644 --- a/src/utils/filterUtils.ts +++ b/src/utils/filterUtils.ts @@ -1,4 +1,4 @@ -import { type FilterExpression } from "./MapLibreRNStyles"; +import { type FilterExpression } from "../types/MapLibreRNStyles"; export function getFilter(filter: FilterExpression | undefined): string[] { if (!Array.isArray(filter) || filter.length === 0) { From 63e8dc93cfb8f5ededdfd6ad92108137db73838f Mon Sep 17 00:00:00 2001 From: Kilian Finger Date: Sun, 15 Dec 2024 16:19:51 +0100 Subject: [PATCH 9/9] fix: drop .d on MapLibreRNStyles.ts --- scripts/codegen.ts | 4 ++-- .../{MapLibreRNStyles.d.ts.ejs => MapLibreRNStyles.ts.ejs} | 1 + src/types/{MapLibreRNStyles.d.ts => MapLibreRNStyles.ts} | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) rename scripts/templates/{MapLibreRNStyles.d.ts.ejs => MapLibreRNStyles.ts.ejs} (99%) rename src/types/{MapLibreRNStyles.d.ts => MapLibreRNStyles.ts} (99%) diff --git a/scripts/codegen.ts b/scripts/codegen.ts index 6c160d01b..2c16cf88d 100644 --- a/scripts/codegen.ts +++ b/scripts/codegen.ts @@ -40,8 +40,8 @@ const TEMPLATE_MAPPINGS = [ output: path.join(IOS_OUTPUT_PATH, "MLRNStyle.h"), }, { - input: path.join(TEMPLATES_PATH, "MapLibreRNStyles.d.ts.ejs"), - output: path.join(JS_OUTPUT_PATH, "types", "MapLibreRNStyles.d.ts"), + input: path.join(TEMPLATES_PATH, "MapLibreRNStyles.ts.ejs"), + output: path.join(JS_OUTPUT_PATH, "types", "MapLibreRNStyles.ts"), }, { input: path.join(TEMPLATES_PATH, "MLRNStyle.m.ejs"), diff --git a/scripts/templates/MapLibreRNStyles.d.ts.ejs b/scripts/templates/MapLibreRNStyles.ts.ejs similarity index 99% rename from scripts/templates/MapLibreRNStyles.d.ts.ejs rename to scripts/templates/MapLibreRNStyles.ts.ejs index 7892eeadb..c4cabeed8 100644 --- a/scripts/templates/MapLibreRNStyles.d.ts.ejs +++ b/scripts/templates/MapLibreRNStyles.ts.ejs @@ -56,6 +56,7 @@ type ExpressionParameters = 'zoom' | 'feature' | 'feature-state' | 'sky-radial-p type ResolvedImageType = ImageSourcePropType | string; +// @ts-ignore // eslint-disable-next-line @typescript-eslint/no-unused-vars export type Value = | T diff --git a/src/types/MapLibreRNStyles.d.ts b/src/types/MapLibreRNStyles.ts similarity index 99% rename from src/types/MapLibreRNStyles.d.ts rename to src/types/MapLibreRNStyles.ts index 2fd501792..f088c04d1 100644 --- a/src/types/MapLibreRNStyles.d.ts +++ b/src/types/MapLibreRNStyles.ts @@ -1,5 +1,5 @@ // DO NOT MODIFY -// This file is auto-generated from scripts/templates/MapLibreRNStyles.d.ts.ejs +// This file is auto-generated from scripts/templates/MapLibreRNStyles.ts.ejs import { type ImageSourcePropType } from "react-native"; @@ -129,6 +129,7 @@ type ExpressionParameters = type ResolvedImageType = ImageSourcePropType | string; +// @ts-ignore // eslint-disable-next-line @typescript-eslint/no-unused-vars export type Value = | T