{"id":26214408,"url":"https://github.com/ljunb/react-native-anchor-tag","last_synced_at":"2025-04-15T18:41:48.782Z","repository":{"id":57335171,"uuid":"97007557","full_name":"ljunb/react-native-anchor-tag","owner":"ljunb","description":"A simple anchor tag view for React Native App.","archived":false,"fork":false,"pushed_at":"2024-03-12T08:26:41.000Z","size":1818,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T23:44:05.658Z","etag":null,"topics":["anchor","react-native","tag"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ljunb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-07-12T12:56:38.000Z","updated_at":"2024-03-12T08:26:45.000Z","dependencies_parsed_at":"2022-08-31T16:43:49.312Z","dependency_job_id":null,"html_url":"https://github.com/ljunb/react-native-anchor-tag","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Freact-native-anchor-tag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Freact-native-anchor-tag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Freact-native-anchor-tag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ljunb%2Freact-native-anchor-tag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ljunb","download_url":"https://codeload.github.com/ljunb/react-native-anchor-tag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248844000,"owners_count":21170499,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["anchor","react-native","tag"],"created_at":"2025-03-12T10:16:55.470Z","updated_at":"2025-04-15T18:41:48.739Z","avatar_url":"https://github.com/ljunb.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# react-native-anchor-tag\n\n[![npm](https://img.shields.io/npm/v/react-native-anchor-tag.svg)](https://www.npmjs.com/package/react-native-anchor-tag)\n[![npm](https://img.shields.io/npm/dt/react-native-anchor-tag.svg)](https://www.npmjs.com/package/react-native-anchor-tag)\n[![npm](https://img.shields.io/npm/l/react-native-anchor-tag.svg)](https://github.com/ljunb/react-native-anchor-tag/blob/master/LICENSE)\n\nA light anchor tag view for react-native apps. You may be used to display some anchor tag information for the image. Written in JS for cross-platform support. Enjoy it! 🎉🎉\n\n## Preview\n\n![ios](https://github.com/ljunb/react-native-anchor-tag/blob/master/screenshot/ios.png)\n![android](https://github.com/ljunb/react-native-anchor-tag/blob/master/screenshot/android.png)\n\n## Install\n\nInstall with npm:\n```\nnpm install react-native-anchor-tag --save\n```\nor with yarn:\n```\nyarn add react-native-anchor-tag\n```\n\n## Demo\n\nSee [RNAnchorTagDemo](https://github.com/ljunb/RNAnchorTagDemo).\n\n## Usage\n\n```js\nimport React, {Component} from 'react';\nimport {\n    StyleSheet,\n    Dimensions,\n    View,\n    Image\n} from 'react-native';\nimport AnchorView from \"react-native-anchor-tag\";\nconst {width: screenW} = Dimensions.get('window');\n\nexport default class RNAnchorTagDemo extends Component {\n    data = {\n        coverHeight: 646,   // source image height\n        coverWidth: 750,    // source image width\n        tagList: [\n            {name: '远处云层', x: 100, y: 150},\n            {name: '明亮的太阳', x: 640, y: 410},\n            {name: '书页', x: 280, y: 460},\n            {name: '木地板', x: 400, y: 600}\n        ]\n    };\n\n    renderAnchorItem = (tag, key) =\u003e {\n        const {coverWidth, coverHeight} = this.data;\n        const {x, y} = tag;\n\n        // expect image width\n        const imgWidth = screenW - 15 * 2;\n        // convert image height base on expect width\n        const imgHeight = imgWidth * coverHeight / coverWidth;\n\n        // convert anchor position base on the expect image layout\n        const convertX = x * imgWidth / coverWidth;\n        const convertY = y * imgHeight / coverHeight;\n\n        return \u003cAnchorView key={key} anchor={{...tag, x: convertX, y: convertY}}/\u003e\n    };\n\n    render() {\n        const {tagList, coverHeight, coverWidth} = this.data;\n        const uri = 'http://img02.tooopen.com/images/20160509/tooopen_sy_161967094653.jpg';\n\n        // convert to expect image layout\n        const imgWidth = screenW - 15 * 2;\n        const imgHeight = imgWidth * coverHeight / coverWidth;\n\n        return (\n            \u003cView style={styles.container}\u003e\n                \u003cImage style={{width: imgWidth, height: imgHeight}} source={{uri}}\u003e\n                    {tagList.map(this.renderAnchorItem)}\n                \u003c/Image\u003e\n            \u003c/View\u003e\n        );\n    }\n}\n\nconst styles = StyleSheet.create({\n    container: {\n        flex: 1,\n        justifyContent: 'center',\n        alignItems: 'center',\n        backgroundColor: '#F5FCFF',\n        padding: 15\n    },\n});\n```\n\n## Props\n\nProp              | Type   | Optional | Default   | Description\n----------------  | ------ | -------- | --------- | -----------\nanchor            | object | No       |           | anchor entity (name, x, y)\nbackgroundWidth   | number | Yes      | screenW - 15*2       | determine the width of the background container that will change the direction of the anchor tag","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljunb%2Freact-native-anchor-tag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fljunb%2Freact-native-anchor-tag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fljunb%2Freact-native-anchor-tag/lists"}