diff --git a/.eslintrc.js b/.eslintrc.js index a2c067fa3..2662550bd 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -85,7 +85,11 @@ module.exports = { files: ['**/*.{ts,tsx}'], parserOptions: { - project: './tsconfig.json', + project: [ + './tsconfig.json', + './example/tsconfig.json', + './plugin/src/__tests__/tsconfig.eslint.json', + ], }, plugins: ['@typescript-eslint'], extends: [ diff --git a/.github/workflows/on-push.yml b/.github/workflows/on-push.yml index 89eff6720..38b1aca3b 100644 --- a/.github/workflows/on-push.yml +++ b/.github/workflows/on-push.yml @@ -33,6 +33,9 @@ jobs: - name: Lint run: yarn lint + - name: Type check + run: yarn type:check + - name: Test run: yarn unittest diff --git a/example/tsconfig.json b/example/tsconfig.json new file mode 100644 index 000000000..c8ef31df1 --- /dev/null +++ b/example/tsconfig.json @@ -0,0 +1,11 @@ +{ + "extends": "../tsconfig.json", + "compilerOptions": { + "baseUrl": ".", + "paths": { + "@rnmapbox/maps": ["../"], + "react": ["./node_modules/@types/react"], + } + }, + "include": ["index.js", "src/**/*", "../index.ts", "../javascript/**/*"] +} \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index d03d64d6f..b8198178d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -22,6 +22,8 @@ import { FeatureCollection, } from '@turf/helpers'; +import type { requestAndroidLocationPermissions as _requestAndroidLocationPermissions } from './javascript/requestAndroidLocationPermissions'; + // prettier-ignore type ExpressionName = // Types @@ -108,7 +110,8 @@ declare namespace MapboxGL { function getAccessToken(): Promise; function setTelemetryEnabled(telemetryEnabled: boolean): void; function setConnected(connected: boolean): void; - function requestAndroidLocationPermissions(): Promise; + + const requestAndroidLocationPermissions = _requestAndroidLocationPermissions; const offlineManager: OfflineManager; const snapshotManager: SnapshotManager; diff --git a/ios/RCTMGL/index.d.ts b/ios/RCTMGL/index.d.ts deleted file mode 100644 index f00f7320d..000000000 --- a/ios/RCTMGL/index.d.ts +++ /dev/null @@ -1,1193 +0,0 @@ -/* eslint-disable */ -// DO NOT MODIFY -// THIS FILE IS AUTOGENERATED - -export interface ConstantProps { - styletype: string; - payload: { - value: any; - }; -} - -export interface StyleFunctionProps { - styletype: string; - payload: { - fn: string; - attributeName: string; - stops: any[]; - mode: any; - }; -} - -export interface TransitionProps { - duration: number; - delay: number; -} - -export type TranslationProps = { x: number; y: number } | number[]; - -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. - */ - fillSortKey: number; - - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * Whether or not the fill should be antialiased. - */ - fillAntialias: string; - - /** - * The opacity of the entire fill layer. In contrast to the `fillColor`, this value will also affect the 1px stroke around the fill, if the stroke is used. - */ - fillOpacity: number; - - /** - * The transition affecting any changes to this layer’s fillOpacity property. - */ - fillOpacityTransition: TransitionProps; - - /** - * The color of the filled part of this layer. This color can be specified as `rgba` with an alpha component and the color's opacity will not affect the opacity of the 1px stroke, if it is used. - * - * @disabledBy fillPattern - */ - fillColor: string; - - /** - * The transition affecting any changes to this layer’s fillColor property. - */ - fillColorTransition: TransitionProps; - - /** - * The outline color of the fill. Matches the value of `fillColor` if unspecified. - * - * @disabledBy fillPattern - */ - fillOutlineColor: string; - - /** - * The transition affecting any changes to this layer’s fillOutlineColor property. - */ - fillOutlineColorTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - */ - fillTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s fillTranslate property. - */ - fillTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `fillTranslate`. - * - * @requires fillTranslate - */ - fillTranslateAnchor: TranslationProps; - - /** - * 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. - */ - fillPattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s fillPattern property. - */ - fillPatternTransition: TransitionProps; -} - -export interface lineLayerStyleProps { - /** - * The display of line endings. - */ - lineCap: any; - - /** - * The display of lines when joining. - */ - lineJoin: TransitionProps | any | StyleFunctionProps; - - /** - * Used to automatically convert miter joins to bevel joins for sharp angles. - */ - lineMiterLimit: number; - - /** - * Used to automatically convert round joins to miter joins for shallow angles. - */ - lineRoundLimit: number; - - /** - * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. - */ - lineSortKey: number; - - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity at which the line will be drawn. - */ - lineOpacity: number; - - /** - * The transition affecting any changes to this layer’s lineOpacity property. - */ - lineOpacityTransition: TransitionProps; - - /** - * The color with which the line will be drawn. - * - * @disabledBy linePattern - */ - lineColor: string; - - /** - * The transition affecting any changes to this layer’s lineColor property. - */ - lineColorTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - */ - lineTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s lineTranslate property. - */ - lineTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `lineTranslate`. - * - * @requires lineTranslate - */ - lineTranslateAnchor: TranslationProps; - - /** - * Stroke thickness. - */ - lineWidth: TransitionProps | number | StyleFunctionProps; - - /** - * The transition affecting any changes to this layer’s lineWidth property. - */ - lineWidthTransition: TransitionProps; - - /** - * Draws a line casing outside of a line's actual path. Value indicates the width of the inner gap. - */ - lineGapWidth: number; - - /** - * The transition affecting any changes to this layer’s lineGapWidth property. - */ - lineGapWidthTransition: TransitionProps; - - /** - * The line's offset. For linear features, a positive value offsets the line to the right, relative to the direction of the line, and a negative value to the left. For polygon features, a positive value results in an inset, and a negative value results in an outset. - */ - lineOffset: number; - - /** - * The transition affecting any changes to this layer’s lineOffset property. - */ - lineOffsetTransition: TransitionProps; - - /** - * Blur applied to the line, in pixels. - */ - lineBlur: number; - - /** - * The transition affecting any changes to this layer’s lineBlur property. - */ - lineBlurTransition: TransitionProps; - - /** - * Specifies the lengths of the alternating dashes and gaps that form the dash pattern. The lengths are later scaled by the line width. To convert a dash length to pixels, multiply the length by the current line width. Note that GeoJSON sources with `lineMetrics: true` specified won't render dashed lines to the expected scale. Also note that zoomDependent expressions will be evaluated only at integer zoom levels. - * - * @disabledBy linePattern - */ - lineDasharray: number[]; - - /** - * The transition affecting any changes to this layer’s lineDasharray property. - */ - lineDasharrayTransition: TransitionProps; - - /** - * Name of image in sprite to use for drawing image lines. For seamless patterns, image width must be a factor of two (2, 4, 8, ..., 512). Note that zoomDependent expressions will be evaluated only at integer zoom levels. - */ - linePattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s linePattern property. - */ - linePatternTransition: TransitionProps; - - /** - * Defines a gradient with which to color a line feature. Can only be used with GeoJSON sources that specify `"lineMetrics": true`. - * - * @disabledBy linePattern - */ - lineGradient: string; -} - -export interface symbolLayerStyleProps { - /** - * Label placement relative to its geometry. - */ - symbolPlacement: any; - - /** - * Distance between two symbol anchors. - */ - symbolSpacing: number; - - /** - * If true, the symbols will not cross tile edges to avoid mutual collisions. Recommended in layers that don't have enough padding in the vector tile to prevent collisions, or if it is a point symbol layer placed after a line symbol layer. When using a client that supports global collision detection, like Mapbox GL JS version 0.42.0 or greater, enabling this property is not needed to prevent clipped labels at tile boundaries. - */ - symbolAvoidEdges: string; - - /** - * Sorts features in ascending order based on this value. Features with lower sort keys are drawn and placed first. When `iconAllowOverlap` or `textAllowOverlap` is `false`, features with a lower sort key will have priority during placement. When `iconAllowOverlap` or `textAllowOverlap` is set to `true`, features with a higher sort key will overlap over features with a lower sort key. - */ - symbolSortKey: number; - - /** - * 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: any; - - /** - * If true, the icon will be visible even if it collides with other previously drawn symbols. - * - * @requires iconImage - */ - iconAllowOverlap: string; - - /** - * If true, other symbols can be visible even if they collide with the icon. - * - * @requires iconImage - */ - iconIgnorePlacement: string; - - /** - * If true, text will display without their corresponding icons when the icon collides with other symbols and the text does not. - * - * @requires iconImage, textField - */ - iconOptional: string; - - /** - * In combination with `symbolPlacement`, determines the rotation behavior of icons. - * - * @requires iconImage - */ - iconRotationAlignment: any; - - /** - * 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. - * - * @requires iconImage - */ - iconSize: number; - - /** - * Scales the icon to fit around the associated text. - * - * @requires iconImage, textField - */ - iconTextFit: any; - - /** - * Size of the additional area added to dimensions determined by `iconTextFit`, in clockwise order: top, right, bottom, left. - * - * @requires iconImage, textField - */ - iconTextFitPadding: number[]; - - /** - * Name of image in sprite to use for drawing an image background. - */ - iconImage: TransitionProps | number | string; - - /** - * Rotates the icon clockwise. - * - * @requires iconImage - */ - iconRotate: number; - - /** - * Size of the additional area around the icon bounding box used for detecting symbol collisions. - * - * @requires iconImage - */ - iconPadding: number; - - /** - * If true, the icon may be flipped to prevent it from being rendered upsideDown. - * - * @requires iconImage - */ - iconKeepUpright: string; - - /** - * Offset distance of icon from its anchor. Positive values indicate right and down, while negative values indicate left and up. Each component is multiplied by the value of `iconSize` to obtain the final offset in pixels. When combined with `iconRotate` the offset will be as if the rotated direction was up. - * - * @requires iconImage - */ - iconOffset: number[]; - - /** - * Part of the icon placed closest to the anchor. - * - * @requires iconImage - */ - iconAnchor: any; - - /** - * Orientation of icon when map is pitched. - * - * @requires iconImage - */ - iconPitchAlignment: any; - - /** - * Orientation of text when map is pitched. - * - * @requires textField - */ - textPitchAlignment: any; - - /** - * In combination with `symbolPlacement`, determines the rotation behavior of the individual glyphs forming the text. - * - * @requires textField - */ - textRotationAlignment: any; - - /** - * Value to use for a text label. If a plain `string` is provided, it will be treated as a `formatted` with default/inherited formatting options. - */ - textField: string; - - /** - * Font stack to use for displaying text. - * - * @requires textField - */ - textFont: TransitionProps | string[] | any[] | StyleFunctionProps; - - /** - * Font size. - * - * @requires textField - */ - textSize: number; - - /** - * The maximum line width for text wrapping. - * - * @requires textField - */ - textMaxWidth: TransitionProps | number | StyleFunctionProps; - - /** - * Text leading value for multiLine text. - * - * @requires textField - */ - textLineHeight: number; - - /** - * Text tracking amount. - * - * @requires textField - */ - textLetterSpacing: TransitionProps | number | StyleFunctionProps; - - /** - * Text justification options. - * - * @requires textField - */ - textJustify: TransitionProps | any | StyleFunctionProps; - - /** - * Radial offset of text, in the direction of the symbol's anchor. Useful in combination with `textVariableAnchor`, which defaults to using the twoDimensional `textOffset` if present. - * - * @requires textField - */ - textRadialOffset: number; - - /** - * To increase the chance of placing highPriority labels on the map, you can provide an array of `textAnchor` locations: the renderer will attempt to place the label at each location, in order, before moving onto the next label. Use `textJustify: auto` to choose justification based on anchor position. To apply an offset, use the `textRadialOffset` or the twoDimensional `textOffset`. - * - * @requires textField - */ - textVariableAnchor: any[]; - - /** - * Part of the text placed closest to the anchor. - * - * @requires textField - * - * @disabledBy textVariableAnchor - */ - textAnchor: TransitionProps | any | StyleFunctionProps; - - /** - * Maximum angle change between adjacent characters. - * - * @requires textField - */ - textMaxAngle: number; - - /** - * The property allows control over a symbol's orientation. Note that the property values act as a hint, so that a symbol whose language doesn’t support the provided orientation will be laid out in its natural orientation. Example: English point symbol will be rendered horizontally even if array value contains single 'vertical' enum value. For symbol with point placement, the order of elements in an array define priority order for the placement of an orientation variant. For symbol with line placement, the default text writing mode is either ['horizontal', 'vertical'] or ['vertical', 'horizontal'], the order doesn't affect the placement. - * - * @requires textField - */ - textWritingMode: any[]; - - /** - * Rotates the text clockwise. - * - * @requires textField - */ - textRotate: number; - - /** - * Size of the additional area around the text bounding box used for detecting symbol collisions. - * - * @requires textField - */ - textPadding: number; - - /** - * If true, the text may be flipped vertically to prevent it from being rendered upsideDown. - * - * @requires textField - */ - textKeepUpright: string; - - /** - * Specifies how to capitalize text, similar to the CSS `textTransform` property. - * - * @requires textField - */ - textTransform: any; - - /** - * Offset distance of text from its anchor. Positive values indicate right and down, while negative values indicate left and up. If used with textVariableAnchor, input values will be taken as absolute values. Offsets along the x and yAxis will be applied automatically based on the anchor position. - * - * @requires textField - * - * @disabledBy textRadialOffset - */ - textOffset: number[]; - - /** - * If true, the text will be visible even if it collides with other previously drawn symbols. - * - * @requires textField - */ - textAllowOverlap: string; - - /** - * If true, other symbols can be visible even if they collide with the text. - * - * @requires textField - */ - textIgnorePlacement: string; - - /** - * If true, icons will display without their corresponding text when the text collides with other symbols and the icon does not. - * - * @requires textField, iconImage - */ - textOptional: string; - - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity at which the icon will be drawn. - * - * @requires iconImage - */ - iconOpacity: number; - - /** - * The transition affecting any changes to this layer’s iconOpacity property. - */ - iconOpacityTransition: TransitionProps; - - /** - * The color of the icon. This can only be used with [SDF icons](/help/troubleshooting/usingRecolorableImagesInMapboxMaps/). - * - * @requires iconImage - */ - iconColor: string; - - /** - * The transition affecting any changes to this layer’s iconColor property. - */ - iconColorTransition: TransitionProps; - - /** - * The color of the icon's halo. Icon halos can only be used with [SDF icons](/help/troubleshooting/usingRecolorableImagesInMapboxMaps/). - * - * @requires iconImage - */ - iconHaloColor: string; - - /** - * The transition affecting any changes to this layer’s iconHaloColor property. - */ - iconHaloColorTransition: TransitionProps; - - /** - * Distance of halo to the icon outline. - * - * @requires iconImage - */ - iconHaloWidth: number; - - /** - * The transition affecting any changes to this layer’s iconHaloWidth property. - */ - iconHaloWidthTransition: TransitionProps; - - /** - * Fade out the halo towards the outside. - * - * @requires iconImage - */ - iconHaloBlur: number; - - /** - * The transition affecting any changes to this layer’s iconHaloBlur property. - */ - iconHaloBlurTransition: TransitionProps; - - /** - * Distance that the icon's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. - * - * @requires iconImage - */ - iconTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s iconTranslate property. - */ - iconTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `iconTranslate`. - * - * @requires iconImage, iconTranslate - */ - iconTranslateAnchor: TranslationProps; - - /** - * The opacity at which the text will be drawn. - * - * @requires textField - */ - textOpacity: number; - - /** - * The transition affecting any changes to this layer’s textOpacity property. - */ - textOpacityTransition: TransitionProps; - - /** - * The color with which the text will be drawn. - * - * @requires textField - */ - textColor: string; - - /** - * The transition affecting any changes to this layer’s textColor property. - */ - textColorTransition: TransitionProps; - - /** - * The color of the text's halo, which helps it stand out from backgrounds. - * - * @requires textField - */ - textHaloColor: string; - - /** - * The transition affecting any changes to this layer’s textHaloColor property. - */ - textHaloColorTransition: TransitionProps; - - /** - * Distance of halo to the font outline. Max text halo width is 1/4 of the fontSize. - * - * @requires textField - */ - textHaloWidth: number; - - /** - * The transition affecting any changes to this layer’s textHaloWidth property. - */ - textHaloWidthTransition: TransitionProps; - - /** - * The halo's fadeout distance towards the outside. - * - * @requires textField - */ - textHaloBlur: number; - - /** - * The transition affecting any changes to this layer’s textHaloBlur property. - */ - textHaloBlurTransition: TransitionProps; - - /** - * Distance that the text's anchor is moved from its original placement. Positive values indicate right and down, while negative values indicate left and up. - * - * @requires textField - */ - textTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s textTranslate property. - */ - textTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `textTranslate`. - * - * @requires textField, textTranslate - */ - textTranslateAnchor: TranslationProps; -} - -export interface circleLayerStyleProps { - /** - * Sorts features in ascending order based on this value. Features with a higher sort key will appear above features with a lower sort key. - */ - circleSortKey: number; - - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * Circle radius. - */ - circleRadius: number; - - /** - * The transition affecting any changes to this layer’s circleRadius property. - */ - circleRadiusTransition: TransitionProps; - - /** - * The fill color of the circle. - */ - circleColor: string; - - /** - * The transition affecting any changes to this layer’s circleColor property. - */ - circleColorTransition: TransitionProps; - - /** - * Amount to blur the circle. 1 blurs the circle such that only the centerpoint is full opacity. - */ - circleBlur: number; - - /** - * The transition affecting any changes to this layer’s circleBlur property. - */ - circleBlurTransition: TransitionProps; - - /** - * The opacity at which the circle will be drawn. - */ - circleOpacity: number; - - /** - * The transition affecting any changes to this layer’s circleOpacity property. - */ - circleOpacityTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up, respectively. - */ - circleTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s circleTranslate property. - */ - circleTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `circleTranslate`. - * - * @requires circleTranslate - */ - circleTranslateAnchor: TranslationProps; - - /** - * Controls the scaling behavior of the circle when the map is pitched. - */ - circlePitchScale: any; - - /** - * Orientation of circle when map is pitched. - */ - circlePitchAlignment: any; - - /** - * The width of the circle's stroke. Strokes are placed outside of the `circleRadius`. - */ - circleStrokeWidth: number; - - /** - * The transition affecting any changes to this layer’s circleStrokeWidth property. - */ - circleStrokeWidthTransition: TransitionProps; - - /** - * The stroke color of the circle. - */ - circleStrokeColor: string; - - /** - * The transition affecting any changes to this layer’s circleStrokeColor property. - */ - circleStrokeColorTransition: TransitionProps; - - /** - * The opacity of the circle's stroke. - */ - circleStrokeOpacity: number; - - /** - * The transition affecting any changes to this layer’s circleStrokeOpacity property. - */ - circleStrokeOpacityTransition: TransitionProps; -} - -export interface heatmapLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * Radius of influence of one heatmap point in pixels. Increasing the value makes the heatmap smoother, but less detailed. `queryRenderedFeatures` on heatmap layers will return points within this radius. - */ - heatmapRadius: number; - - /** - * The transition affecting any changes to this layer’s heatmapRadius property. - */ - heatmapRadiusTransition: TransitionProps; - - /** - * A measure of how much an individual point contributes to the heatmap. A value of 10 would be equivalent to having 10 points of weight 1 in the same spot. Especially useful when combined with clustering. - */ - heatmapWeight: number; - - /** - * Similar to `heatmapWeight` but controls the intensity of the heatmap globally. Primarily used for adjusting the heatmap based on zoom level. - */ - heatmapIntensity: number; - - /** - * The transition affecting any changes to this layer’s heatmapIntensity property. - */ - heatmapIntensityTransition: TransitionProps; - - /** - * Defines the color of each pixel based on its density value in a heatmap. Should be an expression that uses `["heatmapDensity"]` as input. - */ - heatmapColor: string; - - /** - * The global opacity at which the heatmap layer will be drawn. - */ - heatmapOpacity: number; - - /** - * The transition affecting any changes to this layer’s heatmapOpacity property. - */ - heatmapOpacityTransition: TransitionProps; -} - -export interface fillExtrusionLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity of the entire fill extrusion layer. This is rendered on a perLayer, not perFeature, basis, and dataDriven styling is not available. - */ - fillExtrusionOpacity: number; - - /** - * The transition affecting any changes to this layer’s fillExtrusionOpacity property. - */ - fillExtrusionOpacityTransition: TransitionProps; - - /** - * The base color of the extruded fill. The extrusion's surfaces will be shaded differently based on this color in combination with the root `light` settings. If this color is specified as `rgba` with an alpha component, the alpha component will be ignored; use `fillExtrusionOpacity` to set layer opacity. - * - * @disabledBy fillExtrusionPattern - */ - fillExtrusionColor: string; - - /** - * The transition affecting any changes to this layer’s fillExtrusionColor property. - */ - fillExtrusionColorTransition: TransitionProps; - - /** - * The geometry's offset. Values are [x, y] where negatives indicate left and up (on the flat plane), respectively. - */ - fillExtrusionTranslate: TranslationProps; - - /** - * The transition affecting any changes to this layer’s fillExtrusionTranslate property. - */ - fillExtrusionTranslateTransition: TransitionProps; - - /** - * Controls the frame of reference for `fillExtrusionTranslate`. - * - * @requires fillExtrusionTranslate - */ - fillExtrusionTranslateAnchor: TranslationProps; - - /** - * 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. - */ - fillExtrusionPattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s fillExtrusionPattern property. - */ - fillExtrusionPatternTransition: TransitionProps; - - /** - * The height with which to extrude this layer. - */ - fillExtrusionHeight: number; - - /** - * The transition affecting any changes to this layer’s fillExtrusionHeight property. - */ - fillExtrusionHeightTransition: TransitionProps; - - /** - * The height with which to extrude the base of this layer. Must be less than or equal to `fillExtrusionHeight`. - * - * @requires fillExtrusionHeight - */ - fillExtrusionBase: number; - - /** - * The transition affecting any changes to this layer’s fillExtrusionBase property. - */ - fillExtrusionBaseTransition: TransitionProps; - - /** - * Whether to apply a vertical gradient to the sides of a fillExtrusion layer. If true, sides will be shaded slightly darker farther down. - */ - fillExtrusionVerticalGradient: string; -} - -export interface rasterLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The opacity at which the image will be drawn. - */ - rasterOpacity: number; - - /** - * The transition affecting any changes to this layer’s rasterOpacity property. - */ - rasterOpacityTransition: TransitionProps; - - /** - * Rotates hues around the color wheel. - */ - rasterHueRotate: number; - - /** - * The transition affecting any changes to this layer’s rasterHueRotate property. - */ - rasterHueRotateTransition: TransitionProps; - - /** - * Increase or reduce the brightness of the image. The value is the minimum brightness. - */ - rasterBrightnessMin: number; - - /** - * The transition affecting any changes to this layer’s rasterBrightnessMin property. - */ - rasterBrightnessMinTransition: TransitionProps; - - /** - * Increase or reduce the brightness of the image. The value is the maximum brightness. - */ - rasterBrightnessMax: number; - - /** - * The transition affecting any changes to this layer’s rasterBrightnessMax property. - */ - rasterBrightnessMaxTransition: TransitionProps; - - /** - * Increase or reduce the saturation of the image. - */ - rasterSaturation: number; - - /** - * The transition affecting any changes to this layer’s rasterSaturation property. - */ - rasterSaturationTransition: TransitionProps; - - /** - * Increase or reduce the contrast of the image. - */ - rasterContrast: number; - - /** - * The transition affecting any changes to this layer’s rasterContrast property. - */ - rasterContrastTransition: TransitionProps; - - /** - * The resampling/interpolation method to use for overscaling, also known as texture magnification filter - */ - rasterResampling: any; - - /** - * Fade duration when a new tile is added. - */ - rasterFadeDuration: number; -} - -export interface hillshadeLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * 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`. - */ - hillshadeIlluminationDirection: number; - - /** - * Direction of light source when map is rotated. - */ - hillshadeIlluminationAnchor: any; - - /** - * Intensity of the hillshade - */ - hillshadeExaggeration: number; - - /** - * The transition affecting any changes to this layer’s hillshadeExaggeration property. - */ - hillshadeExaggerationTransition: TransitionProps; - - /** - * The shading color of areas that face away from the light source. - */ - hillshadeShadowColor: string; - - /** - * The transition affecting any changes to this layer’s hillshadeShadowColor property. - */ - hillshadeShadowColorTransition: TransitionProps; - - /** - * The shading color of areas that faces towards the light source. - */ - hillshadeHighlightColor: string; - - /** - * The transition affecting any changes to this layer’s hillshadeHighlightColor property. - */ - hillshadeHighlightColorTransition: TransitionProps; - - /** - * The shading color used to accentuate rugged terrain like sharp cliffs and gorges. - */ - hillshadeAccentColor: string; - - /** - * The transition affecting any changes to this layer’s hillshadeAccentColor property. - */ - hillshadeAccentColorTransition: TransitionProps; -} - -export interface backgroundLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The color with which the background will be drawn. - * - * @disabledBy backgroundPattern - */ - backgroundColor: string; - - /** - * The transition affecting any changes to this layer’s backgroundColor property. - */ - backgroundColorTransition: TransitionProps; - - /** - * Name of image in sprite to use for drawing an image background. 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. - */ - backgroundPattern: TransitionProps | number | string; - - /** - * The transition affecting any changes to this layer’s backgroundPattern property. - */ - backgroundPatternTransition: TransitionProps; - - /** - * The opacity at which the background will be drawn. - */ - backgroundOpacity: number; - - /** - * The transition affecting any changes to this layer’s backgroundOpacity property. - */ - backgroundOpacityTransition: TransitionProps; -} - -export interface skyLayerStyleProps { - /** - * Whether this layer is displayed. - */ - visibility: any; - - /** - * The type of the sky - */ - skyType: any; - - /** - * Position of the sun center [a azimuthal angle, p polar angle]. The azimuthal angle indicates the position of the sun relative to 0° north, where degrees proceed clockwise. The polar angle indicates the height of the sun, where 0° is directly above, at zenith, and 90° at the horizon. When this property is ommitted, the sun center is directly inherited from the light position. - */ - skyAtmosphereSun: number[]; - - /** - * Intensity of the sun as a light source in the atmosphere (on a scale from 0 to a 100). Setting higher values will brighten up the sky. - */ - skyAtmosphereSunIntensity: number; - - /** - * Position of the gradient center [a azimuthal angle, p polar angle]. The azimuthal angle indicates the position of the gradient center relative to 0° north, where degrees proceed clockwise. The polar angle indicates the height of the gradient center, where 0° is directly above, at zenith, and 90° at the horizon. - */ - skyGradientCenter: number[]; - - /** - * The angular distance (measured in degrees) from `skyGradientCenter` up to which the gradient extends. A value of 180 causes the gradient to wrap around to the opposite direction from `skyGradientCenter`. - */ - skyGradientRadius: number; - - /** - * Defines a radial color gradient with which to color the sky. The color values can be interpolated with an expression using `skyRadialProgress`. The range [0, 1] for the interpolant covers a radial distance (in degrees) of [0, `skyGradientRadius`] centered at the position specified by `skyGradientCenter`. - */ - skyGradient: string; - - /** - * A color applied to the atmosphere sun halo. The alpha channel describes how strongly the sun halo is represented in an atmosphere sky layer. - */ - skyAtmosphereHaloColor: string; - - /** - * A color used to tweak the main atmospheric scattering coefficients. Using white applies the default coefficients giving the natural blue color to the atmosphere. This color affects how heavily the corresponding wavelength is represented during scattering. The alpha channel describes the density of the atmosphere, with 1 maximum density and 0 no density. - */ - skyAtmosphereColor: string; - - /** - * The opacity of the entire sky layer. - */ - skyOpacity: number; - - /** - * The transition affecting any changes to this layer’s skyOpacity property. - */ - skyOpacityTransition: TransitionProps; -} - -export interface lightLayerStyleProps { - /** - * Whether extruded geometries are lit relative to the map or viewport. - */ - anchor: any; - - /** - * 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). - */ - position: number[]; - - /** - * The transition affecting any changes to this layer’s position property. - */ - positionTransition: TransitionProps; - - /** - * Color tint for lighting extruded geometries. - */ - color: string; - - /** - * The transition affecting any changes to this layer’s color property. - */ - colorTransition: TransitionProps; - - /** - * Intensity of lighting (on a scale from 0 to 1). Higher numbers will present as more extreme contrast. - */ - intensity: number; - - /** - * The transition affecting any changes to this layer’s intensity property. - */ - intensityTransition: TransitionProps; -} diff --git a/javascript/index.js b/javascript/index.js index 193534a43..746eaeb31 100644 --- a/javascript/index.js +++ b/javascript/index.js @@ -1,6 +1,5 @@ -import { NativeModules, PermissionsAndroid } from 'react-native'; +import { NativeModules } from 'react-native'; -import { isAndroid } from './utils'; import MapView from './components/MapView'; import Light from './components/Light'; import PointAnnotation from './components/PointAnnotation'; @@ -36,34 +35,12 @@ import AnimatedExtractCoordinateFromArray from './utils/animated/AnimatedExtract import AnimatedRouteCoordinatesArray from './utils/animated/AnimatedRouteCoordinatesArray'; import Style from './components/Style'; import Logger from './utils/Logger'; +import requestAndroidLocationPermissions from './requestAndroidLocationPermissions'; const MapboxGL = { ...NativeModules.MGLModule }; // static methods -MapboxGL.requestAndroidLocationPermissions = async function () { - if (isAndroid()) { - const res = await PermissionsAndroid.requestMultiple([ - PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, - PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION, - ]); - - if (!res) { - return false; - } - - const permissions = Object.keys(res); - for (const permission of permissions) { - if (res[permission] === PermissionsAndroid.RESULTS.GRANTED) { - return true; - } - } - - return false; - } - - throw new Error('You should only call this method on Android!'); -}; - +MapboxGL.requestAndroidLocationPermissions = requestAndroidLocationPermissions; MapboxGL.UserTrackingModes = Camera.UserTrackingModes; // components diff --git a/javascript/requestAndroidLocationPermissions.ts b/javascript/requestAndroidLocationPermissions.ts new file mode 100644 index 000000000..fc68aab7e --- /dev/null +++ b/javascript/requestAndroidLocationPermissions.ts @@ -0,0 +1,30 @@ +import { number } from 'prop-types'; +import { PermissionsAndroid, Permission } from 'react-native'; + +import { isAndroid } from './utils'; + +export async function requestAndroidLocationPermissions(): Promise { + if (isAndroid()) { + const res = await PermissionsAndroid.requestMultiple([ + PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION, + PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION, + ]); + + if (!res) { + return false; + } + + const permissions: string[] = Object.keys(res); + for (const permission of permissions) { + if ( + res[permission as Permission] === PermissionsAndroid.RESULTS.GRANTED + ) { + return true; + } + } + + return false; + } + + throw new Error('You should only call this method on Android!'); +} diff --git a/package.json b/package.json index b8c3316c9..bf0cc6e64 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ "unittest:single": "jest --testNamePattern", "lint": "eslint .", "lint:fix": "eslint . --fix", - "prepare": "npm run build:plugin", + "type:check": "yarn tsc --noEmit", "test:plugin": "expo-module test plugin", "build:plugin": "tsc --build plugin", "lint:plugin": "eslint plugin/src/*" diff --git a/plugin/src/__tests__/tsconfig.eslint.json b/plugin/src/__tests__/tsconfig.eslint.json new file mode 100644 index 000000000..457a4c369 --- /dev/null +++ b/plugin/src/__tests__/tsconfig.eslint.json @@ -0,0 +1,5 @@ +{ + "compilerOptions": { + }, + "include": ["./**/*"], +} diff --git a/scripts/autogenerate.js b/scripts/autogenerate.js index 02f4bcde4..03cdad674 100644 --- a/scripts/autogenerate.js +++ b/scripts/autogenerate.js @@ -416,10 +416,10 @@ async function generate() { output: path.join(IOS_OUTPUT_PATH, 'RCTMGLStyle.h'), only: 'gl', }, - { + /*{ input: path.join(TMPL_PATH, 'index.d.ts.ejs'), output: path.join(IOS_OUTPUT_PATH, 'index.d.ts'), - }, + },*/ { input: path.join(TMPL_PATH, 'RCTMGLStyle.m.ejs'), output: path.join(IOS_OUTPUT_PATH, 'RCTMGLStyle.m'), diff --git a/tsconfig.json b/tsconfig.json index b3d11464d..81be41ea4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,65 +1,24 @@ { "compilerOptions": { - /* Basic Options */ - "target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */ - "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */ - "lib": ["es6"], /* Specify library files to be included in the compilation. */ - "allowJs": true, /* Allow javascript files to be compiled. */ - // "checkJs": true, /* Report errors in .js files. */ - "jsx": "react-native", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ - // "declaration": true, /* Generates corresponding '.d.ts' file. */ - // "sourceMap": true, /* Generates corresponding '.map' file. */ - // "outFile": "./", /* Concatenate and emit output to single file. */ - // "outDir": "./", /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ - // "removeComments": true, /* Do not emit comments to output. */ - "noEmit": true, /* Do not emit outputs. */ - // "incremental": true, /* Enable incremental compilation */ - // "importHelpers": true, /* Import emit helpers from 'tslib'. */ - // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ - "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ - - /* Strict Type-Checking Options */ - "strict": true, /* Enable all strict type-checking options. */ - // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ - // "strictNullChecks": true, /* Enable strict null checks. */ - // "strictFunctionTypes": true, /* Enable strict checking of function types. */ - // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ - // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ - // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ - - /* Additional Checks */ - // "noUnusedLocals": true, /* Report errors on unused locals. */ - // "noUnusedParameters": true, /* Report errors on unused parameters. */ - // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ - // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ - - /* Module Resolution Options */ - "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ - "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ - "paths": { /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ - "@rnmapbox/maps": ["index.d.ts"], - "react": ["node_modules/@types/react"], - "react-native": ["node_modules/@types/react-native"], - }, - // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ - // "typeRoots": [], /* List of folders to include type definitions from. */ - // "types": [], /* Type declaration files to be included in compilation. */ - "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ - "esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ - // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ - - /* Source Map Options */ - // "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ - // "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */ - // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ - // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ - - /* Experimental Options */ - // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ - // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + // change to true after we transition to TS + "declaration": true, + "preserveSymlinks": true, + "target": "es6", + "module": "es6", + "allowJs": true, + "jsx": "react-native", + "skipLibCheck": true, + "allowSyntheticDefaultImports": true, + "moduleResolution": "node", + "lib": ["es6", "dom"], + "esModuleInterop": true, + "strict": true, + "forceConsistentCasingInFileNames": true, + "outDir": "lib/javascript" }, - "exclude": [ - "node_modules", "babel.config.js", "metro.config.js", "jest.config.js" + "include": [ + "index.js", + "javascript/**/*", + "index.d.ts" ] -} +} \ No newline at end of file