react-native-nano-icons 0.2.1 → 1.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSES.md +40 -0
- package/README.md +165 -12
- package/android/build.gradle +8 -1
- package/android/src/main/java/com/nanoicons/NanoIconFonts.kt +31 -0
- package/android/src/main/java/com/nanoicons/NanoIconView.kt +103 -19
- package/android/src/main/java/com/nanoicons/NanoIconViewManager.kt +42 -18
- package/android/src/main/java/com/nanoicons/NanoIconsFontLoaderModule.kt +72 -11
- package/android/src/main/jni/CMakeLists.txt +38 -0
- package/android/src/main/jni/RNNanoIconsSpec.h +19 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h +11 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.cpp +46 -0
- package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h +41 -0
- package/ios/NanoIconFontResolver.h +5 -0
- package/ios/NanoIconFontResolver.mm +32 -0
- package/ios/NanoIconInlineBaseline.h +4 -0
- package/ios/NanoIconInlineBaseline.mm +190 -0
- package/ios/NanoIconView.h +1 -4
- package/ios/NanoIconView.mm +178 -162
- package/ios/NanoIconsFontLoader.mm +10 -32
- package/lib/commonjs/cli/build.d.ts +16 -3
- package/lib/commonjs/cli/build.js +108 -25
- package/lib/commonjs/cli/buildSymbols.d.ts +26 -0
- package/lib/commonjs/cli/buildSymbols.js +134 -0
- package/lib/commonjs/cli/config.d.ts +4 -2
- package/lib/commonjs/cli/config.js +4 -4
- package/lib/commonjs/cli/expoConfig.d.ts +6 -2
- package/lib/commonjs/cli/expoConfig.js +37 -13
- package/lib/commonjs/cli/index.d.ts +7 -5
- package/lib/commonjs/cli/index.js +27 -14
- package/lib/commonjs/cli/link.d.ts +19 -3
- package/lib/commonjs/cli/link.js +311 -45
- package/lib/commonjs/cli/logger.js +9 -7
- package/lib/commonjs/metro/fontRebuildWatcher.d.ts +62 -0
- package/lib/commonjs/metro/fontRebuildWatcher.js +174 -0
- package/lib/commonjs/metro/index.d.ts +35 -0
- package/lib/commonjs/metro/index.js +92 -0
- package/lib/commonjs/metro/symbolRebuildWatcher.d.ts +19 -0
- package/lib/commonjs/metro/symbolRebuildWatcher.js +76 -0
- package/lib/commonjs/plugin/src/buildFonts.d.ts +3 -3
- package/lib/commonjs/plugin/src/buildFonts.js +5 -15
- package/lib/commonjs/plugin/src/buildSymbols.d.ts +3 -0
- package/lib/commonjs/plugin/src/buildSymbols.js +18 -0
- package/lib/commonjs/plugin/src/index.d.ts +2 -2
- package/lib/commonjs/plugin/src/index.js +10 -4
- package/lib/commonjs/plugin/src/types.d.ts +44 -3
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.d.ts +8 -0
- package/lib/commonjs/plugin/src/withNanoIconsDrawableLinking.js +29 -0
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.d.ts +1 -1
- package/lib/commonjs/plugin/src/withNanoIconsFontLinking.js +6 -13
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.d.ts +8 -0
- package/lib/commonjs/plugin/src/withNanoIconsSymbolLinking.js +37 -0
- package/lib/commonjs/scripts/cli.js +64 -23
- package/lib/commonjs/src/core/flatten/arcs.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/arcs.js +136 -0
- package/lib/commonjs/src/core/flatten/document.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/document.js +164 -0
- package/lib/commonjs/src/core/flatten/dom.d.ts +24 -0
- package/lib/commonjs/src/core/flatten/dom.js +221 -0
- package/lib/commonjs/src/core/flatten/element.d.ts +12 -0
- package/lib/commonjs/src/core/flatten/element.js +97 -0
- package/lib/commonjs/src/core/flatten/geometry.d.ts +21 -0
- package/lib/commonjs/src/core/flatten/geometry.js +85 -0
- package/lib/commonjs/src/core/flatten/index.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/index.js +11 -0
- package/lib/commonjs/src/core/flatten/inherit.d.ts +13 -0
- package/lib/commonjs/src/core/flatten/inherit.js +249 -0
- package/lib/commonjs/src/core/flatten/path.d.ts +19 -0
- package/lib/commonjs/src/core/flatten/path.js +439 -0
- package/lib/commonjs/src/core/flatten/pathops.d.ts +14 -0
- package/lib/commonjs/src/core/flatten/pathops.js +236 -0
- package/lib/commonjs/src/core/flatten/shape.d.ts +29 -0
- package/lib/commonjs/src/core/flatten/shape.js +415 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/clip-path.js +20 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/collapse.js +86 -0
- package/lib/commonjs/src/core/flatten/stages/defs.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/defs.js +49 -0
- package/lib/commonjs/src/core/flatten/stages/discard.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/discard.js +50 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/fill-rule.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/nested-svg.js +131 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/opacity.js +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.d.ts +7 -0
- package/lib/commonjs/src/core/flatten/stages/shapes.js +37 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.d.ts +3 -0
- package/lib/commonjs/src/core/flatten/stages/stroke.js +34 -0
- package/lib/commonjs/src/core/flatten/stages/styles.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/styles.js +29 -0
- package/lib/commonjs/src/core/flatten/stages/use.d.ts +4 -0
- package/lib/commonjs/src/core/flatten/stages/use.js +80 -0
- package/lib/commonjs/src/core/flatten/stages/validate.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages/validate.js +39 -0
- package/lib/commonjs/src/core/flatten/stages.d.ts +2 -0
- package/lib/commonjs/src/core/flatten/stages.js +40 -0
- package/lib/commonjs/src/core/flatten/transform.d.ts +35 -0
- package/lib/commonjs/src/core/flatten/transform.js +221 -0
- package/lib/commonjs/src/core/font/compile.d.ts +2 -1
- package/lib/commonjs/src/core/font/compile.js +19 -7
- package/lib/commonjs/src/core/font/metrics.js +7 -0
- package/lib/commonjs/src/core/font/quadratic.d.ts +2 -0
- package/lib/commonjs/src/core/font/quadratic.js +33 -0
- package/lib/commonjs/src/core/glyph/merge.d.ts +7 -0
- package/lib/commonjs/src/core/glyph/merge.js +59 -0
- package/lib/commonjs/src/core/glyph/parse.d.ts +27 -0
- package/lib/commonjs/src/core/{svg/svg_dom.js → glyph/parse.js} +21 -77
- package/lib/commonjs/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +1 -13
- package/lib/commonjs/src/core/{svg/layers.js → glyph/placement.js} +0 -17
- package/lib/commonjs/src/core/glyph/validate.d.ts +8 -0
- package/lib/commonjs/src/core/glyph/validate.js +33 -0
- package/lib/commonjs/src/core/pathkit/contours.d.ts +75 -0
- package/lib/commonjs/src/core/{svg/svg_pathops.js → pathkit/contours.js} +79 -301
- package/lib/commonjs/src/core/pathkit/evenodd.d.ts +12 -0
- package/lib/commonjs/src/core/pathkit/evenodd.js +37 -0
- package/lib/commonjs/src/core/pathkit/load.d.ts +2 -0
- package/lib/commonjs/src/core/pathkit/load.js +26 -0
- package/lib/commonjs/src/core/pathkit/types.d.ts +69 -0
- package/lib/commonjs/src/core/pathkit/types.js +2 -0
- package/lib/commonjs/src/core/pathkit/winding.d.ts +4 -0
- package/lib/commonjs/src/core/pathkit/winding.js +59 -0
- package/lib/commonjs/src/core/pipeline/config.d.ts +2 -0
- package/lib/commonjs/src/core/pipeline/config.js +6 -0
- package/lib/commonjs/src/core/pipeline/iconPool.d.ts +14 -0
- package/lib/commonjs/src/core/pipeline/iconPool.js +109 -0
- package/lib/commonjs/src/core/pipeline/index.d.ts +5 -3
- package/lib/commonjs/src/core/pipeline/index.js +8 -5
- package/lib/commonjs/src/core/pipeline/prepare.d.ts +20 -0
- package/lib/commonjs/src/core/pipeline/prepare.js +74 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.d.ts +25 -0
- package/lib/commonjs/src/core/pipeline/prepareIcon.js +81 -0
- package/lib/commonjs/src/core/pipeline/prepareSvg.d.ts +6 -0
- package/lib/commonjs/src/core/pipeline/prepareSvg.js +11 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.d.ts +26 -0
- package/lib/commonjs/src/core/pipeline/prepareSymbol.js +79 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.d.ts +1 -0
- package/lib/commonjs/src/core/pipeline/prepareWorker.js +12 -0
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.d.ts +6 -0
- package/lib/commonjs/src/core/pipeline/preparedSvgCache.js +44 -0
- package/lib/commonjs/src/core/pipeline/runFontPipeline.d.ts +22 -0
- package/lib/commonjs/src/core/pipeline/runFontPipeline.js +111 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.d.ts +54 -0
- package/lib/commonjs/src/core/pipeline/runSymbolPipeline.js +161 -0
- package/lib/commonjs/src/core/symbols/contents.d.ts +2 -0
- package/lib/commonjs/src/core/symbols/contents.js +15 -0
- package/lib/commonjs/src/core/symbols/knockout.d.ts +3 -0
- package/lib/commonjs/src/core/symbols/knockout.js +51 -0
- package/lib/commonjs/src/core/symbols/layers.d.ts +36 -0
- package/lib/commonjs/src/core/symbols/layers.js +182 -0
- package/lib/commonjs/src/core/symbols/template.d.ts +22 -0
- package/lib/commonjs/src/core/symbols/template.js +140 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.d.ts +11 -0
- package/lib/commonjs/src/core/symbols/vectorDrawable.js +66 -0
- package/lib/commonjs/src/core/types.d.ts +3 -92
- package/lib/commonjs/src/utils/fingerPrint.d.ts +19 -1
- package/lib/commonjs/src/utils/fingerPrint.js +29 -3
- package/lib/commonjs/src/utils/fontIdentity.d.ts +4 -0
- package/lib/commonjs/src/utils/fontIdentity.js +24 -0
- package/lib/commonjs/src/utils/naming.d.ts +10 -0
- package/lib/commonjs/src/utils/naming.js +49 -0
- package/lib/commonjs/src/utils/packageVersion.d.ts +2 -0
- package/lib/commonjs/src/utils/packageVersion.js +37 -0
- package/lib/commonjs/src/utils/parse.d.ts +0 -1
- package/lib/commonjs/src/utils/parse.js +0 -8
- package/lib/commonjs/src/utils/svgPatterns.d.ts +38 -0
- package/lib/commonjs/src/utils/svgPatterns.js +46 -0
- package/lib/module/const/codegenPrimitives.js +1 -2
- package/lib/module/const/colors.js +1 -2
- package/lib/module/createNanoIconsSet.js +1 -2
- package/lib/module/createNanoIconsSet.native.js +38 -28
- package/lib/module/createNanoIconsSet.shared.js +15 -9
- package/lib/module/createNanoIconsSet.web.js +22 -8
- package/lib/module/devServerFont.js +30 -0
- package/lib/module/devServerFont.web.js +25 -0
- package/lib/module/fontIntegrity.js +99 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.node.js +1 -2
- package/lib/module/loadDynamicFont.js +20 -10
- package/lib/module/nativeFontLoader.js +3 -0
- package/lib/module/nativeFontLoader.web.js +3 -0
- package/lib/module/specs/NanoIconViewNativeComponent.ts +9 -6
- package/lib/module/specs/NativeNanoIconsFontLoader.js +1 -2
- package/lib/module/symbols/index.android.js +42 -0
- package/lib/module/symbols/index.ios.js +35 -0
- package/lib/module/symbols/index.js +35 -0
- package/lib/module/symbols/index.native.js +12 -0
- package/lib/module/symbols/types.js +1 -0
- package/lib/module/types.js +1 -2
- package/lib/module/utils/fingerPrint.js +20 -5
- package/lib/module/utils/fontIdentity.js +20 -0
- package/lib/module/utils/glyphRuntime.js +36 -3
- package/lib/module/utils/naming.js +46 -0
- package/lib/module/utils/packageVersion.js +29 -0
- package/lib/module/utils/parse.js +1 -9
- package/lib/module/utils/runtimeLog.js +12 -0
- package/lib/module/utils/shallowEqualColor.js +1 -2
- package/lib/module/utils/svgPatterns.js +49 -0
- package/lib/module/utils/validateLayerColor.js +24 -0
- package/lib/typescript/src/core/flatten/arcs.d.ts +3 -0
- package/lib/typescript/src/core/flatten/document.d.ts +36 -0
- package/lib/typescript/src/core/flatten/dom.d.ts +25 -0
- package/lib/typescript/src/core/flatten/element.d.ts +13 -0
- package/lib/typescript/src/core/flatten/geometry.d.ts +22 -0
- package/lib/typescript/src/core/flatten/index.d.ts +3 -0
- package/lib/typescript/src/core/flatten/inherit.d.ts +14 -0
- package/lib/typescript/src/core/flatten/path.d.ts +20 -0
- package/lib/typescript/src/core/flatten/pathops.d.ts +15 -0
- package/lib/typescript/src/core/flatten/shape.d.ts +30 -0
- package/lib/typescript/src/core/flatten/stages/clip-path.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/collapse.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/defs.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/discard.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/fill-rule.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/nested-svg.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/opacity.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/shapes.d.ts +8 -0
- package/lib/typescript/src/core/flatten/stages/stroke.d.ts +4 -0
- package/lib/typescript/src/core/flatten/stages/styles.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages/use.d.ts +5 -0
- package/lib/typescript/src/core/flatten/stages/validate.d.ts +3 -0
- package/lib/typescript/src/core/flatten/stages.d.ts +3 -0
- package/lib/typescript/src/core/flatten/transform.d.ts +36 -0
- package/lib/typescript/src/core/glyph/merge.d.ts +8 -0
- package/lib/typescript/src/core/glyph/parse.d.ts +28 -0
- package/lib/typescript/src/core/{svg/layers.d.ts → glyph/placement.d.ts} +2 -14
- package/lib/typescript/src/core/glyph/validate.d.ts +9 -0
- package/lib/typescript/src/core/pathkit/contours.d.ts +76 -0
- package/lib/typescript/src/core/pathkit/evenodd.d.ts +13 -0
- package/lib/typescript/src/core/pathkit/load.d.ts +3 -0
- package/lib/typescript/src/core/pathkit/types.d.ts +70 -0
- package/lib/typescript/src/core/pathkit/winding.d.ts +5 -0
- package/lib/typescript/src/core/symbols/contents.d.ts +3 -0
- package/lib/typescript/src/core/symbols/knockout.d.ts +4 -0
- package/lib/typescript/src/core/symbols/layers.d.ts +37 -0
- package/lib/typescript/src/core/symbols/template.d.ts +23 -0
- package/lib/typescript/src/core/symbols/vectorDrawable.d.ts +12 -0
- package/lib/typescript/src/core/types.d.ts +3 -92
- package/lib/typescript/src/devServerFont.d.ts +4 -0
- package/lib/typescript/src/devServerFont.web.d.ts +4 -0
- package/lib/typescript/src/fontIntegrity.d.ts +24 -0
- package/lib/typescript/src/index.d.ts +1 -0
- package/lib/typescript/src/loadDynamicFont.d.ts +1 -0
- package/lib/typescript/src/nativeFontLoader.d.ts +2 -0
- package/lib/typescript/src/nativeFontLoader.web.d.ts +3 -0
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts +6 -5
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts +1 -0
- package/lib/typescript/src/symbols/index.android.d.ts +33 -0
- package/lib/typescript/src/symbols/index.d.ts +31 -0
- package/lib/typescript/src/symbols/index.ios.d.ts +31 -0
- package/lib/typescript/src/symbols/index.native.d.ts +8 -0
- package/lib/typescript/src/symbols/types.d.ts +24 -0
- package/lib/typescript/src/types.d.ts +7 -0
- package/lib/typescript/src/utils/fingerPrint.d.ts +19 -1
- package/lib/typescript/src/utils/fontIdentity.d.ts +5 -0
- package/lib/typescript/src/utils/glyphRuntime.d.ts +3 -1
- package/lib/typescript/src/utils/naming.d.ts +11 -0
- package/lib/typescript/src/utils/packageVersion.d.ts +3 -0
- package/lib/typescript/src/utils/parse.d.ts +0 -1
- package/lib/typescript/src/utils/runtimeLog.d.ts +5 -0
- package/lib/typescript/src/utils/svgPatterns.d.ts +39 -0
- package/lib/typescript/src/utils/validateLayerColor.d.ts +3 -0
- package/metro.js +1 -0
- package/package.json +37 -11
- package/react-native-nano-icons.podspec +4 -1
- package/react-native.config.js +10 -0
- package/src/specs/NanoIconViewNativeComponent.ts +9 -6
- package/src/specs/NativeNanoIconsFontLoader.ts +1 -0
- package/lib/commonjs/src/core/pipeline/managers.d.ts +0 -11
- package/lib/commonjs/src/core/pipeline/managers.js +0 -104
- package/lib/commonjs/src/core/pipeline/run.d.ts +0 -14
- package/lib/commonjs/src/core/pipeline/run.js +0 -189
- package/lib/commonjs/src/core/svg/svg_dom.d.ts +0 -51
- package/lib/commonjs/src/core/svg/svg_pathops.d.ts +0 -32
- package/lib/module/const/codegenPrimitives.js.map +0 -1
- package/lib/module/const/colors.js.map +0 -1
- package/lib/module/core/font/compile.js +0 -81
- package/lib/module/core/font/compile.js.map +0 -1
- package/lib/module/core/font/metrics.js +0 -37
- package/lib/module/core/font/metrics.js.map +0 -1
- package/lib/module/core/pipeline/config.js +0 -20
- package/lib/module/core/pipeline/config.js.map +0 -1
- package/lib/module/core/pipeline/index.js +0 -5
- package/lib/module/core/pipeline/index.js.map +0 -1
- package/lib/module/core/pipeline/managers.js +0 -94
- package/lib/module/core/pipeline/managers.js.map +0 -1
- package/lib/module/core/pipeline/run.js +0 -204
- package/lib/module/core/pipeline/run.js.map +0 -1
- package/lib/module/core/shims/pathops.py +0 -181
- package/lib/module/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/lib/module/core/svg/layers.js +0 -85
- package/lib/module/core/svg/layers.js.map +0 -1
- package/lib/module/core/svg/svg_dom.js +0 -170
- package/lib/module/core/svg/svg_dom.js.map +0 -1
- package/lib/module/core/svg/svg_pathops.js +0 -750
- package/lib/module/core/svg/svg_pathops.js.map +0 -1
- package/lib/module/core/tsconfig.json +0 -32
- package/lib/module/core/types.js +0 -2
- package/lib/module/core/types.js.map +0 -1
- package/lib/module/createNanoIconsSet.js.map +0 -1
- package/lib/module/createNanoIconsSet.native.js.map +0 -1
- package/lib/module/createNanoIconsSet.shared.js.map +0 -1
- package/lib/module/createNanoIconsSet.web.js.map +0 -1
- package/lib/module/index.js.map +0 -1
- package/lib/module/index.node.js.map +0 -1
- package/lib/module/loadDynamicFont.js.map +0 -1
- package/lib/module/specs/NativeNanoIconsFontLoader.js.map +0 -1
- package/lib/module/types.js.map +0 -1
- package/lib/module/utils/fingerPrint.js.map +0 -1
- package/lib/module/utils/glyphRuntime.js.map +0 -1
- package/lib/module/utils/parse.js.map +0 -1
- package/lib/module/utils/shallowEqualColor.js.map +0 -1
- package/lib/typescript/__tests__/build.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/build.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/clippath.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/fingerprint.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/glyphRuntime.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/link.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/link.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts +0 -2
- package/lib/typescript/__tests__/loadDynamicFont.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts +0 -3
- package/lib/typescript/__tests__/pipeline.e2e.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/placement.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/placement.unit.test.d.ts.map +0 -1
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts +0 -3
- package/lib/typescript/__tests__/svg_dom.unit.test.d.ts.map +0 -1
- package/lib/typescript/cli/build.d.ts +0 -32
- package/lib/typescript/cli/build.d.ts.map +0 -1
- package/lib/typescript/cli/link.d.ts +0 -12
- package/lib/typescript/cli/link.d.ts.map +0 -1
- package/lib/typescript/cli/logger.d.ts +0 -28
- package/lib/typescript/cli/logger.d.ts.map +0 -1
- package/lib/typescript/src/const/codegenPrimitives.d.ts.map +0 -1
- package/lib/typescript/src/const/colors.d.ts.map +0 -1
- package/lib/typescript/src/core/font/compile.d.ts +0 -21
- package/lib/typescript/src/core/font/compile.d.ts.map +0 -1
- package/lib/typescript/src/core/font/metrics.d.ts +0 -2
- package/lib/typescript/src/core/font/metrics.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/config.d.ts +0 -16
- package/lib/typescript/src/core/pipeline/config.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/index.d.ts +0 -4
- package/lib/typescript/src/core/pipeline/index.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/managers.d.ts +0 -12
- package/lib/typescript/src/core/pipeline/managers.d.ts.map +0 -1
- package/lib/typescript/src/core/pipeline/run.d.ts +0 -15
- package/lib/typescript/src/core/pipeline/run.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/layers.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_dom.d.ts +0 -52
- package/lib/typescript/src/core/svg/svg_dom.d.ts.map +0 -1
- package/lib/typescript/src/core/svg/svg_pathops.d.ts +0 -33
- package/lib/typescript/src/core/svg/svg_pathops.d.ts.map +0 -1
- package/lib/typescript/src/core/types.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.native.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.shared.d.ts.map +0 -1
- package/lib/typescript/src/createNanoIconsSet.web.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/index.node.d.ts.map +0 -1
- package/lib/typescript/src/loadDynamicFont.d.ts.map +0 -1
- package/lib/typescript/src/specs/NanoIconViewNativeComponent.d.ts.map +0 -1
- package/lib/typescript/src/specs/NativeNanoIconsFontLoader.d.ts.map +0 -1
- package/lib/typescript/src/types.d.ts.map +0 -1
- package/lib/typescript/src/utils/fingerPrint.d.ts.map +0 -1
- package/lib/typescript/src/utils/glyphRuntime.d.ts.map +0 -1
- package/lib/typescript/src/utils/parse.d.ts.map +0 -1
- package/lib/typescript/src/utils/shallowEqualColor.d.ts.map +0 -1
- package/plugin/src/buildFonts.ts +0 -42
- package/plugin/src/index.ts +0 -21
- package/plugin/src/types.ts +0 -42
- package/plugin/src/withNanoIconsFontLinking.ts +0 -136
- package/plugin/tsconfig.json +0 -9
- package/scripts/cli.ts +0 -63
- package/scripts/tsconfig.json +0 -25
- package/src/const/colors.ts +0 -150
- package/src/core/font/compile.ts +0 -99
- package/src/core/font/metrics.ts +0 -44
- package/src/core/pipeline/config.ts +0 -25
- package/src/core/pipeline/index.ts +0 -3
- package/src/core/pipeline/managers.ts +0 -132
- package/src/core/pipeline/run.ts +0 -274
- package/src/core/shims/pathops.py +0 -181
- package/src/core/shims/picosvg-0.22.3-py3-none-any.whl +0 -0
- package/src/core/svg/layers.ts +0 -110
- package/src/core/svg/svg_dom.ts +0 -194
- package/src/core/svg/svg_pathops.ts +0 -1040
- package/src/core/tsconfig.json +0 -32
- package/src/core/types.ts +0 -157
- package/src/createNanoIconsSet.native.tsx +0 -192
- package/src/createNanoIconsSet.shared.tsx +0 -174
- package/src/createNanoIconsSet.tsx +0 -20
- package/src/createNanoIconsSet.web.tsx +0 -109
- package/src/index.node.ts +0 -14
- package/src/index.ts +0 -6
- package/src/loadDynamicFont.ts +0 -162
- package/src/types.ts +0 -31
- package/src/utils/fingerPrint.ts +0 -20
- package/src/utils/glyphRuntime.ts +0 -46
- package/src/utils/parse.ts +0 -67
- package/src/utils/shallowEqualColor.ts +0 -17
|
@@ -4,10 +4,12 @@ import android.graphics.Typeface
|
|
|
4
4
|
import android.net.Uri
|
|
5
5
|
import com.facebook.react.bridge.Promise
|
|
6
6
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
7
|
-
import com.facebook.react.
|
|
7
|
+
import com.facebook.react.bridge.UiThreadUtil
|
|
8
8
|
import java.io.File
|
|
9
9
|
import java.io.InputStream
|
|
10
10
|
import java.net.URL
|
|
11
|
+
import java.nio.ByteBuffer
|
|
12
|
+
import java.nio.charset.Charset
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* Registers a dynamically-linked (OTA) font at runtime so the NanoIconView can
|
|
@@ -23,21 +25,43 @@ class NanoIconsFontLoaderModule(reactContext: ReactApplicationContext) :
|
|
|
23
25
|
override fun getName(): String = NAME
|
|
24
26
|
|
|
25
27
|
override fun registerFont(family: String, uri: String, promise: Promise) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
val bytes =
|
|
29
|
+
try {
|
|
30
|
+
openStream(uri).use { it.readBytes() }
|
|
31
|
+
} catch (e: Exception) {
|
|
32
|
+
promise.reject(REGISTER_CODE, "Could not read font at $uri", e)
|
|
33
|
+
return
|
|
30
34
|
}
|
|
31
35
|
|
|
36
|
+
val postScriptName = runCatching { TtfNames.postScriptName(bytes) }.getOrNull()
|
|
37
|
+
if (postScriptName == null) {
|
|
38
|
+
promise.reject(REGISTER_CODE, "Invalid font data")
|
|
39
|
+
return
|
|
40
|
+
}
|
|
41
|
+
if (postScriptName != family) {
|
|
42
|
+
promise.reject(
|
|
43
|
+
"E_NANOICONS_FONT_MISMATCH",
|
|
44
|
+
"Font name \"$postScriptName\" does not match family \"$family\". " +
|
|
45
|
+
"The TTF PostScript name must equal glyphMap.m.f."
|
|
46
|
+
)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
try {
|
|
51
|
+
val cacheFile = File.createTempFile("nanoicon_", ".ttf", reactApplicationContext.cacheDir)
|
|
52
|
+
cacheFile.writeBytes(bytes)
|
|
32
53
|
val typeface = Typeface.createFromFile(cacheFile)
|
|
33
|
-
|
|
54
|
+
NanoIconFonts.register(family, typeface)
|
|
34
55
|
promise.resolve(true)
|
|
35
56
|
} catch (e: Exception) {
|
|
36
|
-
promise.reject(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
57
|
+
promise.reject(REGISTER_CODE, "Invalid font data", e)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
override fun isFontRegistered(family: String, promise: Promise) {
|
|
62
|
+
val assets = reactApplicationContext.assets
|
|
63
|
+
UiThreadUtil.runOnUiThread {
|
|
64
|
+
promise.resolve(NanoIconFonts.resolve(family, assets) != null)
|
|
41
65
|
}
|
|
42
66
|
}
|
|
43
67
|
|
|
@@ -59,5 +83,42 @@ class NanoIconsFontLoaderModule(reactContext: ReactApplicationContext) :
|
|
|
59
83
|
|
|
60
84
|
companion object {
|
|
61
85
|
const val NAME = "NanoIconsFontLoader"
|
|
86
|
+
private const val REGISTER_CODE = "E_NANOICONS_FONT_REGISTER"
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
object TtfNames {
|
|
91
|
+
private const val NAME_ID_POSTSCRIPT = 6
|
|
92
|
+
|
|
93
|
+
fun postScriptName(bytes: ByteArray): String? {
|
|
94
|
+
val buf = ByteBuffer.wrap(bytes)
|
|
95
|
+
val numTables = buf.getShort(4).toInt() and 0xffff
|
|
96
|
+
var nameOffset = -1
|
|
97
|
+
for (i in 0 until numTables) {
|
|
98
|
+
val record = 12 + i * 16
|
|
99
|
+
val tag = String(bytes, record, 4, Charsets.US_ASCII)
|
|
100
|
+
if (tag == "name") {
|
|
101
|
+
nameOffset = buf.getInt(record + 8)
|
|
102
|
+
break
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (nameOffset < 0) return null
|
|
106
|
+
|
|
107
|
+
val count = buf.getShort(nameOffset + 2).toInt() and 0xffff
|
|
108
|
+
val stringsOffset = nameOffset + (buf.getShort(nameOffset + 4).toInt() and 0xffff)
|
|
109
|
+
var postScript: String? = null
|
|
110
|
+
for (i in 0 until count) {
|
|
111
|
+
val record = nameOffset + 6 + i * 12
|
|
112
|
+
val platformId = buf.getShort(record).toInt() and 0xffff
|
|
113
|
+
val nameId = buf.getShort(record + 6).toInt() and 0xffff
|
|
114
|
+
if (nameId != NAME_ID_POSTSCRIPT) continue
|
|
115
|
+
val length = buf.getShort(record + 8).toInt() and 0xffff
|
|
116
|
+
val offset = buf.getShort(record + 10).toInt() and 0xffff
|
|
117
|
+
val charset: Charset =
|
|
118
|
+
if (platformId == 1) Charsets.ISO_8859_1 else Charsets.UTF_16BE
|
|
119
|
+
val value = String(bytes, stringsOffset + offset, length, charset)
|
|
120
|
+
if (postScript == null || platformId == 3) postScript = value
|
|
121
|
+
}
|
|
122
|
+
return postScript
|
|
62
123
|
}
|
|
63
124
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
cmake_minimum_required(VERSION 3.13)
|
|
2
|
+
set(CMAKE_VERBOSE_MAKEFILE on)
|
|
3
|
+
|
|
4
|
+
set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
|
|
5
|
+
set(LIB_COMMON_DIR ${LIB_ANDROID_DIR}/../common/cpp)
|
|
6
|
+
set(LIB_COMMON_COMPONENTS_DIR ${LIB_COMMON_DIR}/react/renderer/components/RNNanoIconsSpec)
|
|
7
|
+
set(LIB_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
|
|
8
|
+
set(LIB_GENERATED_COMPONENTS_DIR ${LIB_GENERATED_JNI_DIR}/react/renderer/components/RNNanoIconsSpec)
|
|
9
|
+
|
|
10
|
+
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS
|
|
11
|
+
${LIB_GENERATED_JNI_DIR}/*.cpp
|
|
12
|
+
${LIB_GENERATED_COMPONENTS_DIR}/*.cpp
|
|
13
|
+
${LIB_COMMON_COMPONENTS_DIR}/*.cpp
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
add_library(
|
|
17
|
+
react_codegen_RNNanoIconsSpec
|
|
18
|
+
OBJECT
|
|
19
|
+
${react_codegen_SRCS}
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
target_include_directories(
|
|
23
|
+
react_codegen_RNNanoIconsSpec
|
|
24
|
+
PUBLIC
|
|
25
|
+
.
|
|
26
|
+
${LIB_COMMON_DIR}
|
|
27
|
+
${LIB_GENERATED_JNI_DIR}
|
|
28
|
+
${LIB_GENERATED_COMPONENTS_DIR}
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
target_link_libraries(
|
|
32
|
+
react_codegen_RNNanoIconsSpec
|
|
33
|
+
fbjni
|
|
34
|
+
jsi
|
|
35
|
+
reactnative
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
target_compile_reactnative_options(react_codegen_RNNanoIconsSpec PRIVATE)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <ReactCommon/JavaTurboModule.h>
|
|
4
|
+
#include <ReactCommon/TurboModule.h>
|
|
5
|
+
#include <jsi/jsi.h>
|
|
6
|
+
|
|
7
|
+
#include <react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h>
|
|
8
|
+
|
|
9
|
+
namespace facebook::react {
|
|
10
|
+
|
|
11
|
+
class JSI_EXPORT NativeNanoIconsFontLoaderSpecJSI : public JavaTurboModule {
|
|
12
|
+
public:
|
|
13
|
+
NativeNanoIconsFontLoaderSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
JSI_EXPORT
|
|
17
|
+
std::shared_ptr<TurboModule> RNNanoIconsSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
18
|
+
|
|
19
|
+
} // namespace facebook::react
|
package/common/cpp/react/renderer/components/RNNanoIconsSpec/NanoIconViewComponentDescriptor.h
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/RNNanoIconsSpec/NanoIconViewShadowNode.h>
|
|
4
|
+
#include <react/renderer/core/ConcreteComponentDescriptor.h>
|
|
5
|
+
|
|
6
|
+
namespace facebook::react {
|
|
7
|
+
|
|
8
|
+
using NanoIconViewComponentDescriptor =
|
|
9
|
+
ConcreteComponentDescriptor<NanoIconViewShadowNode>;
|
|
10
|
+
|
|
11
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#include "NanoIconViewShadowNode.h"
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/core/LayoutConstraints.h>
|
|
4
|
+
#include <react/renderer/core/LayoutContext.h>
|
|
5
|
+
|
|
6
|
+
namespace facebook::react {
|
|
7
|
+
|
|
8
|
+
extern const char NanoIconViewComponentName[] = "NanoIconView";
|
|
9
|
+
|
|
10
|
+
Size NanoIconViewShadowNode::measureContent(
|
|
11
|
+
const LayoutContext &layoutContext,
|
|
12
|
+
const LayoutConstraints &layoutConstraints) const {
|
|
13
|
+
const auto &props = getConcreteProps();
|
|
14
|
+
const Float height =
|
|
15
|
+
props.size * (props.allowFontScaling ? layoutContext.fontSizeMultiplier : 1);
|
|
16
|
+
const Float width = props.unitsPerEm > 0
|
|
17
|
+
? height * static_cast<Float>(props.advanceWidth) / static_cast<Float>(props.unitsPerEm)
|
|
18
|
+
: height;
|
|
19
|
+
return layoutConstraints.clamp({width, height});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
bool NanoIconViewShadowNode::shouldNewRevisionDirtyMeasurement(
|
|
23
|
+
const ShadowNode & /*sourceShadowNode*/,
|
|
24
|
+
const ShadowNodeFragment & /*fragment*/) const {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void NanoIconViewShadowNode::completeClone(
|
|
29
|
+
const ShadowNode &sourceShadowNode,
|
|
30
|
+
const ShadowNodeFragment &fragment) {
|
|
31
|
+
ConcreteViewShadowNode::completeClone(sourceShadowNode, fragment);
|
|
32
|
+
if (fragment.props == nullptr) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const auto &oldProps =
|
|
36
|
+
static_cast<const NanoIconViewProps &>(*sourceShadowNode.getProps());
|
|
37
|
+
const auto &newProps = getConcreteProps();
|
|
38
|
+
if (oldProps.size != newProps.size ||
|
|
39
|
+
oldProps.allowFontScaling != newProps.allowFontScaling ||
|
|
40
|
+
oldProps.advanceWidth != newProps.advanceWidth ||
|
|
41
|
+
oldProps.unitsPerEm != newProps.unitsPerEm) {
|
|
42
|
+
dirtyLayout();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <react/renderer/components/RNNanoIconsSpec/EventEmitters.h>
|
|
4
|
+
#include <react/renderer/components/RNNanoIconsSpec/Props.h>
|
|
5
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
6
|
+
#include <jsi/jsi.h>
|
|
7
|
+
|
|
8
|
+
namespace facebook::react {
|
|
9
|
+
|
|
10
|
+
JSI_EXPORT extern const char NanoIconViewComponentName[];
|
|
11
|
+
|
|
12
|
+
class JSI_EXPORT NanoIconViewShadowNode final
|
|
13
|
+
: public ConcreteViewShadowNode<
|
|
14
|
+
NanoIconViewComponentName,
|
|
15
|
+
NanoIconViewProps,
|
|
16
|
+
NanoIconViewEventEmitter> {
|
|
17
|
+
public:
|
|
18
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
19
|
+
|
|
20
|
+
static ShadowNodeTraits BaseTraits() {
|
|
21
|
+
auto traits = ConcreteViewShadowNode::BaseTraits();
|
|
22
|
+
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
|
|
23
|
+
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
|
|
24
|
+
return traits;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Size measureContent(
|
|
28
|
+
const LayoutContext &layoutContext,
|
|
29
|
+
const LayoutConstraints &layoutConstraints) const override;
|
|
30
|
+
|
|
31
|
+
void completeClone(
|
|
32
|
+
const ShadowNode &sourceShadowNode,
|
|
33
|
+
const ShadowNodeFragment &fragment) override;
|
|
34
|
+
|
|
35
|
+
protected:
|
|
36
|
+
bool shouldNewRevisionDirtyMeasurement(
|
|
37
|
+
const ShadowNode &sourceShadowNode,
|
|
38
|
+
const ShadowNodeFragment &fragment) const override;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
} // namespace facebook::react
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#import "NanoIconFontResolver.h"
|
|
2
|
+
|
|
3
|
+
static NSMutableDictionary *sNanoIconFontCache;
|
|
4
|
+
static dispatch_once_t sNanoIconFontCacheOnce;
|
|
5
|
+
|
|
6
|
+
CTFontRef NanoIconResolveFont(NSString *family, CGFloat size) {
|
|
7
|
+
dispatch_once(&sNanoIconFontCacheOnce, ^{ sNanoIconFontCache = [NSMutableDictionary new]; });
|
|
8
|
+
|
|
9
|
+
NSString *key = [NSString stringWithFormat:@"%@:%.1f", family, size];
|
|
10
|
+
@synchronized(sNanoIconFontCache) {
|
|
11
|
+
id existing = sNanoIconFontCache[key];
|
|
12
|
+
if (existing) {
|
|
13
|
+
return (__bridge CTFontRef)existing;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)family, size, NULL);
|
|
17
|
+
if (!font) return NULL;
|
|
18
|
+
|
|
19
|
+
NSString *postScriptName = (__bridge_transfer NSString *)CTFontCopyPostScriptName(font);
|
|
20
|
+
if (![postScriptName isEqualToString:family]) {
|
|
21
|
+
CFRelease(font);
|
|
22
|
+
return NULL;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
sNanoIconFontCache[key] = (__bridge id)font;
|
|
26
|
+
return font;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
BOOL NanoIconIsFontResolvable(NSString *family) {
|
|
31
|
+
return NanoIconResolveFont(family, 12.0) != NULL;
|
|
32
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
#import "NanoIconInlineBaseline.h"
|
|
2
|
+
#import "NanoIconView.h"
|
|
3
|
+
#import <React/RCTVersion.h>
|
|
4
|
+
#import <React/RCTViewComponentView.h>
|
|
5
|
+
#import <react/renderer/textlayoutmanager/RCTAttributedTextUtils.h>
|
|
6
|
+
#import <objc/runtime.h>
|
|
7
|
+
#import <vector>
|
|
8
|
+
|
|
9
|
+
// RN <= 0.81 puts an inline view's bottom exactly on the text baseline.
|
|
10
|
+
// Since 0.82 (facebook/react-native#53341) the frame is `line bottom + descender
|
|
11
|
+
// of the attachment run's font`, and that run only carries the NSTextStorage
|
|
12
|
+
// default font, so the view lands below the baseline by an amount that
|
|
13
|
+
// depends on the text's font size and lineHeight.
|
|
14
|
+
static BOOL NanoIconReactNativePlacesInlineViewsOffBaseline(void) {
|
|
15
|
+
static BOOL result;
|
|
16
|
+
static dispatch_once_t once;
|
|
17
|
+
dispatch_once(&once, ^{
|
|
18
|
+
NSDictionary *version = RCTGetReactNativeVersion();
|
|
19
|
+
NSInteger major = [version[RCTVersionMajor] integerValue];
|
|
20
|
+
NSInteger minor = [version[RCTVersionMinor] integerValue];
|
|
21
|
+
result = major > 0 || minor >= 82;
|
|
22
|
+
});
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// The paragraph view is the direct superview of an inline icon; a couple of
|
|
27
|
+
// extra levels cover wrappers RN may insert. nil for standalone icons and on
|
|
28
|
+
// RN <= 0.81, so those never pay for a layout.
|
|
29
|
+
static void NanoIconInstallParagraphUpdateHook(Class paragraphClass);
|
|
30
|
+
|
|
31
|
+
UIView *NanoIconParagraphNeedingBaselineCorrection(UIView *view) {
|
|
32
|
+
if (!NanoIconReactNativePlacesInlineViewsOffBaseline()) return nil;
|
|
33
|
+
UIView *current = view.superview;
|
|
34
|
+
for (int depth = 0; depth < 3 && current; depth++) {
|
|
35
|
+
if ([NSStringFromClass([current class]) isEqualToString:@"RCTParagraphComponentView"]) {
|
|
36
|
+
NanoIconInstallParagraphUpdateHook([current class]);
|
|
37
|
+
return current;
|
|
38
|
+
}
|
|
39
|
+
current = current.superview;
|
|
40
|
+
}
|
|
41
|
+
return nil;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Text is laid out inside the paragraph's content frame (bounds minus
|
|
45
|
+
// padding). RCTViewComponentView keeps it in a protected ivar.
|
|
46
|
+
static CGRect NanoIconContentFrame(UIView *paragraph) {
|
|
47
|
+
static Ivar ivar = class_getInstanceVariable([RCTViewComponentView class], "_layoutMetrics");
|
|
48
|
+
if (ivar) {
|
|
49
|
+
const auto &metrics = *reinterpret_cast<const facebook::react::LayoutMetrics *>(
|
|
50
|
+
reinterpret_cast<const uint8_t *>((__bridge const void *)paragraph) + ivar_getOffset(ivar));
|
|
51
|
+
facebook::react::Rect content = metrics.getContentFrame();
|
|
52
|
+
if (content.size.width > 0 && content.size.height > 0) {
|
|
53
|
+
return CGRectMake(content.origin.x, content.origin.y, content.size.width, content.size.height);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return paragraph.bounds;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@interface NanoIconParagraphBaselines : NSObject
|
|
60
|
+
@property (nonatomic, readonly) std::vector<CGPoint> &entries;
|
|
61
|
+
@end
|
|
62
|
+
|
|
63
|
+
@implementation NanoIconParagraphBaselines {
|
|
64
|
+
std::vector<CGPoint> _entries;
|
|
65
|
+
}
|
|
66
|
+
- (std::vector<CGPoint> &)entries { return _entries; }
|
|
67
|
+
@end
|
|
68
|
+
|
|
69
|
+
static const void *kNanoIconParagraphBaselinesKey = &kNanoIconParagraphBaselinesKey;
|
|
70
|
+
|
|
71
|
+
static void NanoIconInvalidateIconsIn(UIView *view, int depth) {
|
|
72
|
+
for (UIView *child in view.subviews) {
|
|
73
|
+
if ([child isKindOfClass:[NanoIconView class]]) {
|
|
74
|
+
[(NanoIconView *)child invalidateInlineBaseline];
|
|
75
|
+
} else if (depth > 1) {
|
|
76
|
+
NanoIconInvalidateIconsIn(child, depth - 1);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// A text change that keeps an icon's frame (same line bottom, different font
|
|
82
|
+
// or lineHeight) still moves the baseline, and RN only notifies children whose
|
|
83
|
+
// layout changed. The paragraph's state update is the one signal that covers
|
|
84
|
+
// every text change, so its icons are invalidated from there.
|
|
85
|
+
static void NanoIconInstallParagraphUpdateHook(Class paragraphClass) {
|
|
86
|
+
static dispatch_once_t once;
|
|
87
|
+
dispatch_once(&once, ^{
|
|
88
|
+
SEL selector = @selector(updateState:oldState:);
|
|
89
|
+
Method method = class_getInstanceMethod(paragraphClass, selector);
|
|
90
|
+
if (!method) return;
|
|
91
|
+
using StateRef = const facebook::react::State::Shared &;
|
|
92
|
+
auto original = reinterpret_cast<void (*)(id, SEL, StateRef, StateRef)>(method_getImplementation(method));
|
|
93
|
+
IMP hooked = imp_implementationWithBlock(^(UIView *paragraph, StateRef state, StateRef oldState) {
|
|
94
|
+
original(paragraph, selector, state, oldState);
|
|
95
|
+
objc_setAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
96
|
+
NanoIconInvalidateIconsIn(paragraph, 3);
|
|
97
|
+
});
|
|
98
|
+
method_setImplementation(method, hooked);
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Lays the paragraph out again the way RCTTextLayoutManager does (same
|
|
103
|
+
// container settings and lineHeight baseline offset) and records where TextKit
|
|
104
|
+
// put the baseline of every attachment. Layout stops after the last attachment.
|
|
105
|
+
static NanoIconParagraphBaselines *NanoIconLayOutBaselines(UIView *paragraph, NSAttributedString *text) {
|
|
106
|
+
CGRect content = NanoIconContentFrame(paragraph);
|
|
107
|
+
NSTextContainer *container = [[NSTextContainer alloc] initWithSize:content.size];
|
|
108
|
+
container.lineFragmentPadding = 0;
|
|
109
|
+
container.lineBreakMode = NSLineBreakByClipping;
|
|
110
|
+
NSLayoutManager *layoutManager = [NSLayoutManager new];
|
|
111
|
+
layoutManager.usesFontLeading = NO;
|
|
112
|
+
[layoutManager addTextContainer:container];
|
|
113
|
+
NSTextStorage *storage = [[NSTextStorage alloc] initWithAttributedString:text];
|
|
114
|
+
RCTApplyBaselineOffset(storage);
|
|
115
|
+
[storage addLayoutManager:layoutManager];
|
|
116
|
+
|
|
117
|
+
__block NSUInteger lastAttachmentEnd = 0;
|
|
118
|
+
[storage enumerateAttribute:NSAttachmentAttributeName
|
|
119
|
+
inRange:NSMakeRange(0, storage.length)
|
|
120
|
+
options:0
|
|
121
|
+
usingBlock:^(NSTextAttachment *attachment, NSRange range, __unused BOOL *stop) {
|
|
122
|
+
if (attachment) lastAttachmentEnd = NSMaxRange(range);
|
|
123
|
+
}];
|
|
124
|
+
if (lastAttachmentEnd == 0) return nil;
|
|
125
|
+
[layoutManager ensureLayoutForCharacterRange:NSMakeRange(0, lastAttachmentEnd)];
|
|
126
|
+
|
|
127
|
+
NanoIconParagraphBaselines *baselines = [NanoIconParagraphBaselines new];
|
|
128
|
+
std::vector<CGPoint> &entries = baselines.entries;
|
|
129
|
+
[storage enumerateAttribute:NSAttachmentAttributeName
|
|
130
|
+
inRange:NSMakeRange(0, lastAttachmentEnd)
|
|
131
|
+
options:0
|
|
132
|
+
usingBlock:^(NSTextAttachment *attachment, NSRange range, __unused BOOL *stop) {
|
|
133
|
+
if (!attachment) return;
|
|
134
|
+
NSUInteger glyphIndex = [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:NULL].location;
|
|
135
|
+
CGRect line = [layoutManager lineFragmentRectForGlyphAtIndex:glyphIndex effectiveRange:NULL];
|
|
136
|
+
CGPoint location = [layoutManager locationForGlyphAtIndex:glyphIndex];
|
|
137
|
+
entries.push_back(CGPointMake(content.origin.x + location.x,
|
|
138
|
+
content.origin.y + line.origin.y + location.y));
|
|
139
|
+
}];
|
|
140
|
+
return baselines;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// One layout per paragraph per layout pass: the result is kept on the
|
|
144
|
+
// paragraph view until the next main-queue turn so sibling icons reuse it.
|
|
145
|
+
static NanoIconParagraphBaselines *NanoIconBaselinesForParagraph(UIView *paragraph) {
|
|
146
|
+
NanoIconParagraphBaselines *cached = objc_getAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey);
|
|
147
|
+
if (cached) return cached;
|
|
148
|
+
|
|
149
|
+
NSAttributedString *text = nil;
|
|
150
|
+
if ([paragraph respondsToSelector:@selector(attributedText)]) {
|
|
151
|
+
text = [paragraph performSelector:@selector(attributedText)];
|
|
152
|
+
}
|
|
153
|
+
if (text.length == 0) return nil;
|
|
154
|
+
|
|
155
|
+
NanoIconParagraphBaselines *baselines = NanoIconLayOutBaselines(paragraph, text);
|
|
156
|
+
if (!baselines) return nil;
|
|
157
|
+
|
|
158
|
+
objc_setAssociatedObject(paragraph, kNanoIconParagraphBaselinesKey, baselines, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
159
|
+
__weak UIView *weakParagraph = paragraph;
|
|
160
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
161
|
+
UIView *strongParagraph = weakParagraph;
|
|
162
|
+
if (strongParagraph) {
|
|
163
|
+
objc_setAssociatedObject(strongParagraph, kNanoIconParagraphBaselinesKey, nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
return baselines;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Distance from the view's bottom edge down to the baseline RN meant it to
|
|
170
|
+
// sit on, rounded to the pixel grid. The attachment is matched by x; the
|
|
171
|
+
// nearest baseline resolves lines that start at the same x.
|
|
172
|
+
CGFloat NanoIconInlineBaselineOffset(UIView *view, UIView *paragraph) {
|
|
173
|
+
NanoIconParagraphBaselines *baselines = NanoIconBaselinesForParagraph(paragraph);
|
|
174
|
+
if (!baselines) return 0;
|
|
175
|
+
|
|
176
|
+
CGRect frame = [view.superview convertRect:view.frame toView:paragraph];
|
|
177
|
+
CGFloat bottom = CGRectGetMaxY(frame);
|
|
178
|
+
CGFloat nearest = bottom;
|
|
179
|
+
CGFloat nearestDistance = CGFLOAT_MAX;
|
|
180
|
+
for (const CGPoint &baseline : baselines.entries) {
|
|
181
|
+
if (fabs(baseline.x - frame.origin.x) > 1.5) continue;
|
|
182
|
+
CGFloat distance = fabs(baseline.y - bottom);
|
|
183
|
+
if (distance < nearestDistance) {
|
|
184
|
+
nearestDistance = distance;
|
|
185
|
+
nearest = baseline.y;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
CGFloat scale = [UIScreen mainScreen].scale;
|
|
189
|
+
return round((bottom - nearest) * scale) / scale;
|
|
190
|
+
}
|
package/ios/NanoIconView.h
CHANGED
|
@@ -2,8 +2,5 @@
|
|
|
2
2
|
#import <Foundation/Foundation.h>
|
|
3
3
|
|
|
4
4
|
@interface NanoIconView : RCTViewComponentView
|
|
5
|
+
- (void)invalidateInlineBaseline;
|
|
5
6
|
@end
|
|
6
|
-
|
|
7
|
-
// Clears cached CTFontRef entries for `family` so the next render fetches a
|
|
8
|
-
// fresh reference after an OTA font re-registration within the same process.
|
|
9
|
-
void NanoIconInvalidateFontCache(NSString *family);
|