From 98cf9d82acc8975ffb88ce3fa6ba61b20a933431 Mon Sep 17 00:00:00 2001 From: Andrea Franz Date: Tue, 24 Nov 2020 12:29:25 +0100 Subject: [PATCH] add base ios files --- .editorconfig | 15 + .gitignore | 9 +- babel.config.js | 3 + index.js | 6 - ios/StatusKeycard-Bridging-Header.h | 1 + ios/StatusKeycard.m | 9 + ios/StatusKeycard.swift | 8 + ios/StatusKeycard.xcodeproj/project.pbxproj | 297 ++++++++++++++++++++ package.json | 133 ++++++++- react-native-status-keycard.podspec | 21 ++ src/__tests__/index.test.tsx | 1 + src/index.tsx | 9 + tsconfig.json | 27 ++ 13 files changed, 525 insertions(+), 14 deletions(-) create mode 100644 .editorconfig create mode 100644 babel.config.js delete mode 100644 index.js create mode 100644 ios/StatusKeycard-Bridging-Header.h create mode 100644 ios/StatusKeycard.m create mode 100644 ios/StatusKeycard.swift create mode 100644 ios/StatusKeycard.xcodeproj/project.pbxproj create mode 100644 react-native-status-keycard.podspec create mode 100644 src/__tests__/index.test.tsx create mode 100644 src/index.tsx create mode 100644 tsconfig.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..65365be --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +# EditorConfig helps developers define and maintain consistent +# coding styles between different editors and IDEs +# editorconfig.org + +root = true + +[*] + +indent_style = space +indent_size = 2 + +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitignore b/.gitignore index 9cadbfe..12ce940 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ +/example +# # OSX # .DS_Store @@ -8,7 +10,7 @@ node_modules/ npm-debug.log yarn-error.log - + # Xcode # @@ -29,7 +31,7 @@ DerivedData *.ipa *.xcuserstate project.xcworkspace - + # Android/IntelliJ # @@ -43,4 +45,5 @@ local.properties buck-out/ \.buckd/ *.keystore - \ No newline at end of file + +/lib diff --git a/babel.config.js b/babel.config.js new file mode 100644 index 0000000..f842b77 --- /dev/null +++ b/babel.config.js @@ -0,0 +1,3 @@ +module.exports = { + presets: ['module:metro-react-native-babel-preset'], +}; diff --git a/index.js b/index.js deleted file mode 100644 index c2ae151..0000000 --- a/index.js +++ /dev/null @@ -1,6 +0,0 @@ - -import { NativeModules } from 'react-native'; - -const { RNStatusKeycard } = NativeModules; - -export default RNStatusKeycard; diff --git a/ios/StatusKeycard-Bridging-Header.h b/ios/StatusKeycard-Bridging-Header.h new file mode 100644 index 0000000..5fff35c --- /dev/null +++ b/ios/StatusKeycard-Bridging-Header.h @@ -0,0 +1 @@ +#import diff --git a/ios/StatusKeycard.m b/ios/StatusKeycard.m new file mode 100644 index 0000000..b0ae4ef --- /dev/null +++ b/ios/StatusKeycard.m @@ -0,0 +1,9 @@ +#import + +@interface RCT_EXTERN_MODULE(StatusKeycard, NSObject) + +RCT_EXTERN_METHOD(multiply:(float)a withB:(float)b + withResolver:(RCTPromiseResolveBlock)resolve + withRejecter:(RCTPromiseRejectBlock)reject) + +@end diff --git a/ios/StatusKeycard.swift b/ios/StatusKeycard.swift new file mode 100644 index 0000000..5e5742d --- /dev/null +++ b/ios/StatusKeycard.swift @@ -0,0 +1,8 @@ +@objc(StatusKeycard) +class StatusKeycard: NSObject { + + @objc(multiply:withB:withResolver:withRejecter:) + func multiply(a: Float, b: Float, resolve:RCTPromiseResolveBlock,reject:RCTPromiseRejectBlock) -> Void { + resolve(a*b) + } +} diff --git a/ios/StatusKeycard.xcodeproj/project.pbxproj b/ios/StatusKeycard.xcodeproj/project.pbxproj new file mode 100644 index 0000000..a462e71 --- /dev/null +++ b/ios/StatusKeycard.xcodeproj/project.pbxproj @@ -0,0 +1,297 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + + + F4FF95D7245B92E800C19C63 /* StatusKeycard.swift in Sources */ = {isa = PBXBuildFile; fileRef = F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */; }; + + 5E555C0D2413F4C50049A1A2 /* StatusKeycard.mm in Sources */ = {isa = PBXBuildFile; fileRef = B3E7B5891CC2AC0600A0062D /* StatusKeycard.mm */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 58B511D91A9E6C8500147676 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = "include/$(PRODUCT_NAME)"; + dstSubfolderSpec = 16; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 134814201AA4EA6300B7C361 /* libStatusKeycard.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libStatusKeycard.a; sourceTree = BUILT_PRODUCTS_DIR; }; + + + B3E7B5891CC2AC0600A0062D /* StatusKeycard.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StatusKeycard.m; sourceTree = ""; }; + F4FF95D5245B92E700C19C63 /* StatusKeycard-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "StatusKeycard-Bridging-Header.h"; sourceTree = ""; }; + F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusKeycard.swift; sourceTree = ""; }; + +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 58B511D81A9E6C8500147676 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 134814211AA4EA7D00B7C361 /* Products */ = { + isa = PBXGroup; + children = ( + 134814201AA4EA6300B7C361 /* libStatusKeycard.a */, + ); + name = Products; + sourceTree = ""; + }; + 58B511D21A9E6C8500147676 = { + isa = PBXGroup; + children = ( + + + F4FF95D6245B92E800C19C63 /* StatusKeycard.swift */, + B3E7B5891CC2AC0600A0062D /* StatusKeycard.m */, + F4FF95D5245B92E700C19C63 /* StatusKeycard-Bridging-Header.h */, + + 134814211AA4EA7D00B7C361 /* Products */, + ); + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 58B511DA1A9E6C8500147676 /* StatusKeycard */ = { + isa = PBXNativeTarget; + buildConfigurationList = 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "StatusKeycard" */; + buildPhases = ( + 58B511D71A9E6C8500147676 /* Sources */, + 58B511D81A9E6C8500147676 /* Frameworks */, + 58B511D91A9E6C8500147676 /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = StatusKeycard; + productName = RCTDataManager; + productReference = 134814201AA4EA6300B7C361 /* libStatusKeycard.a */; + productType = "com.apple.product-type.library.static"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 58B511D31A9E6C8500147676 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0920; + ORGANIZATIONNAME = Facebook; + TargetAttributes = { + 58B511DA1A9E6C8500147676 = { + CreatedOnToolsVersion = 6.1.1; + }; + }; + }; + buildConfigurationList = 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "StatusKeycard" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + English, + en, + ); + mainGroup = 58B511D21A9E6C8500147676; + productRefGroup = 58B511D21A9E6C8500147676; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 58B511DA1A9E6C8500147676 /* StatusKeycard */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXSourcesBuildPhase section */ + 58B511D71A9E6C8500147676 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + + + F4FF95D7245B92E800C19C63 /* StatusKeycard.swift in Sources */, + B3E7B58A1CC2AC0600A0062D /* StatusKeycard.m in Sources */, + + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 58B511ED1A9E6C8500147676 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 58B511EE1A9E6C8500147676 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 58B511F01A9E6C8500147676 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../../React/**", + "$(SRCROOT)/../../react-native/React/**", + ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = StatusKeycard; + SKIP_INSTALL = YES; + + SWIFT_OBJC_BRIDGING_HEADER = "StatusKeycard-Bridging-Header.h"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; + + }; + name = Debug; + }; + 58B511F11A9E6C8500147676 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + HEADER_SEARCH_PATHS = ( + "$(inherited)", + /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include, + "$(SRCROOT)/../../../React/**", + "$(SRCROOT)/../../react-native/React/**", + ); + LIBRARY_SEARCH_PATHS = "$(inherited)"; + OTHER_LDFLAGS = "-ObjC"; + PRODUCT_NAME = StatusKeycard; + SKIP_INSTALL = YES; + + SWIFT_OBJC_BRIDGING_HEADER = "StatusKeycard-Bridging-Header.h"; + SWIFT_VERSION = 5.0; + + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 58B511D61A9E6C8500147676 /* Build configuration list for PBXProject "StatusKeycard" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58B511ED1A9E6C8500147676 /* Debug */, + 58B511EE1A9E6C8500147676 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 58B511EF1A9E6C8500147676 /* Build configuration list for PBXNativeTarget "StatusKeycard" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 58B511F01A9E6C8500147676 /* Debug */, + 58B511F11A9E6C8500147676 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 58B511D31A9E6C8500147676 /* Project object */; +} diff --git a/package.json b/package.json index 12a4be6..1e96159 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,135 @@ { "name": "react-native-status-keycard", - "homepage": "https://keycard.status.im/", "version": "2.5.27", - "description": "React Native library to interact with Status Keycard using NFC connection (Android only)", - "main": "index.js", + "description": "React Native library to interact with Status Keycard using NFC connection", + "main": "lib/commonjs/index", + "module": "lib/module/index", + "types": "lib/typescript/src/index.d.ts", + "react-native": "src/index", + "source": "src/index", + "files": [ + "src", + "lib", + "android", + "ios", + "cpp", + "react-native-status-keycard.podspec", + "!lib/typescript/example", + "!**/__tests__", + "!**/__fixtures__", + "!**/__mocks__" + ], "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" + "test": "jest", + "typescript": "tsc --noEmit", + "lint": "eslint \"**/*.{js,ts,tsx}\"", + "prepare": "bob build", + "release": "release-it", + "example": "yarn --cwd example", + "pods": "cd example && pod-install --quiet", + "bootstrap": "yarn example && yarn && yarn pods" }, + "keywords": [ + "react-native", + "ios", + "android" + ], + "repository": "https://github.com/status-im/react-native-status-keycard", "author": "Dmitry Novotochinov", - "license": "MPL 2.0" + "license": "MPL 2.0", + "bugs": { + "url": "https://github.com/status-im/react-native-status-keycard/issues" + }, + "homepage": "https://github.com/status-im/react-native-status-keycard#readme", + "devDependencies": { + "@commitlint/config-conventional": "^8.3.4", + "@react-native-community/bob": "^0.16.2", + "@react-native-community/eslint-config": "^2.0.0", + "@release-it/conventional-changelog": "^1.1.4", + "@types/jest": "^26.0.0", + "@types/react": "^16.9.19", + "@types/react-native": "0.62.13", + "commitlint": "^8.3.5", + "eslint": "^7.2.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-prettier": "^3.1.3", + "husky": "^4.2.5", + "jest": "^26.0.1", + "pod-install": "^0.1.0", + "prettier": "^2.0.5", + "react": "16.11.0", + "react-native": "0.62.2", + "release-it": "^13.5.8", + "typescript": "^3.8.3" + }, + "peerDependencies": { + "react": "*", + "react-native": "*" + }, + "jest": { + "preset": "react-native", + "modulePathIgnorePatterns": [ + "/example/node_modules", + "/lib/" + ] + }, + "husky": { + "hooks": { + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", + "pre-commit": "yarn lint && yarn typescript" + } + }, + "commitlint": { + "extends": [ + "@commitlint/config-conventional" + ] + }, + "release-it": { + "git": { + "commitMessage": "chore: release ${version}", + "tagName": "v${version}" + }, + "npm": { + "publish": true + }, + "github": { + "release": true + }, + "plugins": { + "@release-it/conventional-changelog": { + "preset": "angular" + } + } + }, + "eslintConfig": { + "extends": [ + "@react-native-community", + "prettier" + ], + "rules": { + "prettier/prettier": [ + "error", + { + "quoteProps": "consistent", + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false + } + ] + } + }, + "eslintIgnore": ["node_modules/", "lib/"], + "prettier": { + "quoteProps": "consistent", + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "es5", + "useTabs": false + }, + "@react-native-community/bob": { + "source": "src", + "output": "lib", + "targets": ["commonjs", "module", "typescript"] + } } diff --git a/react-native-status-keycard.podspec b/react-native-status-keycard.podspec new file mode 100644 index 0000000..3fa42f5 --- /dev/null +++ b/react-native-status-keycard.podspec @@ -0,0 +1,21 @@ +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) + +Pod::Spec.new do |s| + s.name = "react-native-status-keycard" + s.version = package["version"] + s.summary = package["description"] + s.homepage = package["homepage"] + s.license = package["license"] + s.authors = package["author"] + + s.platforms = { :ios => "9.0" } + s.source = { :git => "https://github.com/status-im/react-native-status-keycard.git", :tag => "#{s.version}" } + + + s.source_files = "ios/**/*.{h,m,mm,swift}" + + + s.dependency "React" +end diff --git a/src/__tests__/index.test.tsx b/src/__tests__/index.test.tsx new file mode 100644 index 0000000..bf84291 --- /dev/null +++ b/src/__tests__/index.test.tsx @@ -0,0 +1 @@ +it.todo('write a test'); diff --git a/src/index.tsx b/src/index.tsx new file mode 100644 index 0000000..8423e86 --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,9 @@ +import { NativeModules } from 'react-native'; + +type StatusKeycardType = { + multiply(a: number, b: number): Promise; +}; + +const { StatusKeycard } = NativeModules; + +export default StatusKeycard as StatusKeycardType; diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..3cfe82a --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "baseUrl": ".", + "paths": { + "react-native-status-keycard": ["./src/index"] + }, + "allowUnreachableCode": false, + "allowUnusedLabels": false, + "esModuleInterop": true, + "importsNotUsedAsValues": "error", + "forceConsistentCasingInFileNames": true, + "jsx": "react", + "lib": ["esnext"], + "module": "esnext", + "moduleResolution": "node", + "noFallthroughCasesInSwitch": true, + "noImplicitReturns": true, + "noImplicitUseStrict": false, + "noStrictGenericChecks": false, + "noUnusedLocals": true, + "noUnusedParameters": true, + "resolveJsonModule": true, + "skipLibCheck": true, + "strict": true, + "target": "esnext" + } +}