diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..97de990 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='-Dfile.encoding=UTF-8 "-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/iosApp/.gitignore b/iosApp/.gitignore new file mode 100644 index 0000000..eac567d --- /dev/null +++ b/iosApp/.gitignore @@ -0,0 +1,48 @@ +# Xcode +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata/ +*.xccheckout +*.moved-aside +DerivedData/ +*.hmap +*.ipa +*.xcuserstate +*.xcscmblueprint + +# CocoaPods +Pods/ +*.xcworkspace +Podfile.lock + +# Carthage +Carthage/Build/ + +# Swift Package Manager +.build/ +.swiftpm/ + +# fastlane +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots +fastlane/test_output + +# Code Injection +iOSInjectionProject/ + +# OS generated files +.DS_Store +.DS_Store? +._* +.Spotlight-V100 +.Trashes +ehthumbs.db +Thumbs.db diff --git a/iosApp/.swiftlint.yml b/iosApp/.swiftlint.yml new file mode 100644 index 0000000..523fde9 --- /dev/null +++ b/iosApp/.swiftlint.yml @@ -0,0 +1,51 @@ +disabled_rules: + - trailing_whitespace + - line_length + - file_length + - type_body_length + - function_body_length + +opt_in_rules: + - empty_count + - empty_string + - closure_spacing + - contains_over_first_not_nil + - discouraged_object_literal + - explicit_init + - first_where + - implicit_return + - joined_default_parameter + - modifier_order + - overridden_super_call + - private_action + - private_outlet + - redundant_nil_coalescing + - sorted_first_last + - toggle_bool + - unneeded_parentheses_in_closure_argument + +included: + - iosApp + +excluded: + - Pods + - iosAppTests + +identifier_name: + min_length: 1 + max_length: 60 + excluded: + - id + - i + - x + - y + - r + - g + - b + - a + +type_name: + min_length: 3 + max_length: 60 + +reporter: "xcode" diff --git a/iosApp/Podfile b/iosApp/Podfile new file mode 100644 index 0000000..5413846 --- /dev/null +++ b/iosApp/Podfile @@ -0,0 +1,17 @@ +use_frameworks! +platform :ios, '16.0' + +target 'iosApp' do + pod 'shared', :path => '../shared' +end + +post_install do |installer| + installer.pods_project.targets.each do |target| + target.build_configurations.each do |config| + config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '16.0' + # Link sqlite3 for SQLDelight + config.build_settings['OTHER_LDFLAGS'] ||= ['$(inherited)'] + config.build_settings['OTHER_LDFLAGS'] << '-lsqlite3' + end + end +end diff --git a/iosApp/iosApp.xcodeproj/project.pbxproj b/iosApp/iosApp.xcodeproj/project.pbxproj new file mode 100644 index 0000000..3fa9853 --- /dev/null +++ b/iosApp/iosApp.xcodeproj/project.pbxproj @@ -0,0 +1,516 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 56; + objects = { + +/* Begin PBXBuildFile section */ + A0001 /* iOSApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0001 /* iOSApp.swift */; }; + A0002 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0002 /* ContentView.swift */; }; + A0003 /* StateFlowExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0003 /* StateFlowExtensions.swift */; }; + A0004 /* PokemonColors.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0004 /* PokemonColors.swift */; }; + A0005 /* PokemonListStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0005 /* PokemonListStore.swift */; }; + A0006 /* PokemonDetailStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0006 /* PokemonDetailStore.swift */; }; + A0007 /* FavoritesStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0007 /* FavoritesStore.swift */; }; + A0008 /* KoinHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0008 /* KoinHelper.swift */; }; + A0009 /* PokemonListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0009 /* PokemonListView.swift */; }; + A0010 /* PokemonGridCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0010 /* PokemonGridCell.swift */; }; + A0011 /* PokemonDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0011 /* PokemonDetailView.swift */; }; + A0012 /* TypeChip.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0012 /* TypeChip.swift */; }; + A0013 /* StatBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0013 /* StatBar.swift */; }; + A0014 /* FlowLayout.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0014 /* FlowLayout.swift */; }; + A0015 /* FavoritesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0015 /* FavoritesView.swift */; }; + A0016 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = B0016 /* Assets.xcassets */; }; + DA52813C6ABE90128F960957 /* Pods_iosApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9418996CBB2D1204986CB8DA /* Pods_iosApp.framework */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 9418996CBB2D1204986CB8DA /* Pods_iosApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_iosApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + A8468446D3CB31BFD2296622 /* Pods-iosApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.release.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.release.xcconfig"; sourceTree = ""; }; + B0001 /* iOSApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = iOSApp.swift; sourceTree = ""; }; + B0002 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; + B0003 /* StateFlowExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateFlowExtensions.swift; sourceTree = ""; }; + B0004 /* PokemonColors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonColors.swift; sourceTree = ""; }; + B0005 /* PokemonListStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonListStore.swift; sourceTree = ""; }; + B0006 /* PokemonDetailStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonDetailStore.swift; sourceTree = ""; }; + B0007 /* FavoritesStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesStore.swift; sourceTree = ""; }; + B0008 /* KoinHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KoinHelper.swift; sourceTree = ""; }; + B0009 /* PokemonListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonListView.swift; sourceTree = ""; }; + B0010 /* PokemonGridCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonGridCell.swift; sourceTree = ""; }; + B0011 /* PokemonDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PokemonDetailView.swift; sourceTree = ""; }; + B0012 /* TypeChip.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TypeChip.swift; sourceTree = ""; }; + B0013 /* StatBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatBar.swift; sourceTree = ""; }; + B0014 /* FlowLayout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlowLayout.swift; sourceTree = ""; }; + B0015 /* FavoritesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesView.swift; sourceTree = ""; }; + B0016 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + B0017 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + B0018 /* iosApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iosApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + ED1F59DAF3DF34B51A7357C1 /* Pods-iosApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-iosApp.debug.xcconfig"; path = "Target Support Files/Pods-iosApp/Pods-iosApp.debug.xcconfig"; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + F0001 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + DA52813C6ABE90128F960957 /* Pods_iosApp.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 8E8358AD1380D791DCE15B1F /* Pods */ = { + isa = PBXGroup; + children = ( + ED1F59DAF3DF34B51A7357C1 /* Pods-iosApp.debug.xcconfig */, + A8468446D3CB31BFD2296622 /* Pods-iosApp.release.xcconfig */, + ); + name = Pods; + path = Pods; + sourceTree = ""; + }; + DABF9B40361964ECDAB38690 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 9418996CBB2D1204986CB8DA /* Pods_iosApp.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; + G0001 = { + isa = PBXGroup; + children = ( + G0002 /* iosApp */, + G0003 /* Products */, + 8E8358AD1380D791DCE15B1F /* Pods */, + DABF9B40361964ECDAB38690 /* Frameworks */, + ); + sourceTree = ""; + }; + G0002 /* iosApp */ = { + isa = PBXGroup; + children = ( + G0004 /* App */, + G0005 /* Utilities */, + G0006 /* Stores */, + G0007 /* Views */, + G0012 /* Resources */, + B0017 /* Info.plist */, + ); + path = iosApp; + sourceTree = ""; + }; + G0003 /* Products */ = { + isa = PBXGroup; + children = ( + B0018 /* iosApp.app */, + ); + name = Products; + sourceTree = ""; + }; + G0004 /* App */ = { + isa = PBXGroup; + children = ( + B0001 /* iOSApp.swift */, + B0002 /* ContentView.swift */, + ); + path = App; + sourceTree = ""; + }; + G0005 /* Utilities */ = { + isa = PBXGroup; + children = ( + B0003 /* StateFlowExtensions.swift */, + B0004 /* PokemonColors.swift */, + ); + path = Utilities; + sourceTree = ""; + }; + G0006 /* Stores */ = { + isa = PBXGroup; + children = ( + B0005 /* PokemonListStore.swift */, + B0006 /* PokemonDetailStore.swift */, + B0007 /* FavoritesStore.swift */, + B0008 /* KoinHelper.swift */, + ); + path = Stores; + sourceTree = ""; + }; + G0007 /* Views */ = { + isa = PBXGroup; + children = ( + G0008 /* PokemonList */, + G0009 /* PokemonDetail */, + G0010 /* Favorites */, + G0011 /* Components */, + ); + path = Views; + sourceTree = ""; + }; + G0008 /* PokemonList */ = { + isa = PBXGroup; + children = ( + B0009 /* PokemonListView.swift */, + B0010 /* PokemonGridCell.swift */, + ); + path = PokemonList; + sourceTree = ""; + }; + G0009 /* PokemonDetail */ = { + isa = PBXGroup; + children = ( + B0011 /* PokemonDetailView.swift */, + ); + path = PokemonDetail; + sourceTree = ""; + }; + G0010 /* Favorites */ = { + isa = PBXGroup; + children = ( + B0015 /* FavoritesView.swift */, + ); + path = Favorites; + sourceTree = ""; + }; + G0011 /* Components */ = { + isa = PBXGroup; + children = ( + B0012 /* TypeChip.swift */, + B0013 /* StatBar.swift */, + B0014 /* FlowLayout.swift */, + ); + path = Components; + sourceTree = ""; + }; + G0012 /* Resources */ = { + isa = PBXGroup; + children = ( + B0016 /* Assets.xcassets */, + ); + path = Resources; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + T0001 /* iosApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = C0003 /* Build configuration list for PBXNativeTarget "iosApp" */; + buildPhases = ( + 896C188BC0482ED96FFA9834 /* [CP] Check Pods Manifest.lock */, + S0001 /* Sources */, + F0001 /* Frameworks */, + R0001 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = iosApp; + productName = iosApp; + productReference = B0018 /* iosApp.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + P0001 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1540; + LastUpgradeCheck = 1540; + TargetAttributes = { + T0001 = { + CreatedOnToolsVersion = 15.4; + }; + }; + }; + buildConfigurationList = C0001 /* Build configuration list for PBXProject "iosApp" */; + compatibilityVersion = "Xcode 14.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = G0001; + productRefGroup = G0003 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + T0001 /* iosApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + R0001 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A0016 /* Assets.xcassets in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 896C188BC0482ED96FFA9834 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", + ); + name = "[CP] Check Pods Manifest.lock"; + outputFileListPaths = ( + ); + outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-iosApp-checkManifestLockResult.txt", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + S0001 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + A0001 /* iOSApp.swift in Sources */, + A0002 /* ContentView.swift in Sources */, + A0003 /* StateFlowExtensions.swift in Sources */, + A0004 /* PokemonColors.swift in Sources */, + A0005 /* PokemonListStore.swift in Sources */, + A0006 /* PokemonDetailStore.swift in Sources */, + A0007 /* FavoritesStore.swift in Sources */, + A0008 /* KoinHelper.swift in Sources */, + A0009 /* PokemonListView.swift in Sources */, + A0010 /* PokemonGridCell.swift in Sources */, + A0011 /* PokemonDetailView.swift in Sources */, + A0012 /* TypeChip.swift in Sources */, + A0013 /* StatBar.swift in Sources */, + A0014 /* FlowLayout.swift in Sources */, + A0015 /* FavoritesView.swift in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + BC0001 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + 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_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + 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 = 16.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + BC0002 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + 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_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GCC_C_LANGUAGE_STANDARD = gnu17; + 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 = 16.0; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + BC0003 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = ED1F59DAF3DF34B51A7357C1 /* Pods-iosApp.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = ""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = iosApp/Info.plist; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.assignment.pokemon.iosApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + BC0004 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = A8468446D3CB31BFD2296622 /* Pods-iosApp.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = ""; + ENABLE_PREVIEWS = YES; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_FILE = iosApp/Info.plist; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = com.assignment.pokemon.iosApp; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + C0001 /* Build configuration list for PBXProject "iosApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BC0001 /* Debug */, + BC0002 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + C0003 /* Build configuration list for PBXNativeTarget "iosApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + BC0003 /* Debug */, + BC0004 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = P0001 /* Project object */; +} diff --git a/iosApp/iosApp/App/ContentView.swift b/iosApp/iosApp/App/ContentView.swift new file mode 100644 index 0000000..ebd6212 --- /dev/null +++ b/iosApp/iosApp/App/ContentView.swift @@ -0,0 +1,32 @@ +import SwiftUI +import shared + +struct ContentView: View { + @State private var selectedTab: Tab = .list + + var body: some View { + TabView(selection: $selectedTab) { + PokemonListView() + .tabItem { + Label("Pokédex", systemImage: "list.bullet.rectangle") + } + .tag(Tab.list) + + FavoritesView() + .tabItem { + Label("Favorites", systemImage: "heart.fill") + } + .tag(Tab.favorites) + } + .tint(PokemonColors.primary) + } +} + +enum Tab: Hashable { + case list + case favorites +} + +#Preview { + ContentView() +} diff --git a/iosApp/iosApp/App/iOSApp.swift b/iosApp/iosApp/App/iOSApp.swift new file mode 100644 index 0000000..4c07ac1 --- /dev/null +++ b/iosApp/iosApp/App/iOSApp.swift @@ -0,0 +1,19 @@ +import SwiftUI +import shared + +@main +struct iOSApp: App { + init() { + ModulesKt.doInitKoin( + driverFactory: DatabaseDriverFactory(), + enableNetworkLogs: true, + appDeclaration: { _ in } + ) + } + + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/iosApp/iosApp/Info.plist b/iosApp/iosApp/Info.plist new file mode 100644 index 0000000..c55b268 --- /dev/null +++ b/iosApp/iosApp/Info.plist @@ -0,0 +1,53 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + $(PRODUCT_BUNDLE_PACKAGE_TYPE) + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + + UILaunchScreen + + UIColorName + LaunchScreenBackground + UIImageName + LaunchScreenIcon + + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UISupportedInterfaceOrientations~ipad + + UIInterfaceOrientationPortrait + UIInterfaceOrientationPortraitUpsideDown + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/iosApp/iosApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json b/iosApp/iosApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 0000000..38b11c0 --- /dev/null +++ b/iosApp/iosApp/Resources/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.392", + "green" : "0.298", + "red" : "0.929" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.490", + "green" : "0.400", + "red" : "0.980" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json b/iosApp/iosApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..13613e3 --- /dev/null +++ b/iosApp/iosApp/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Resources/Assets.xcassets/AppPrimaryColor.colorset/Contents.json b/iosApp/iosApp/Resources/Assets.xcassets/AppPrimaryColor.colorset/Contents.json new file mode 100644 index 0000000..84d2cb2 --- /dev/null +++ b/iosApp/iosApp/Resources/Assets.xcassets/AppPrimaryColor.colorset/Contents.json @@ -0,0 +1,38 @@ +{ + "colors" : [ + { + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.216", + "green" : "0.204", + "red" : "0.800" + } + }, + "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "srgb", + "components" : { + "alpha" : "1.000", + "blue" : "0.314", + "green" : "0.298", + "red" : "0.878" + } + }, + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Resources/Assets.xcassets/Contents.json b/iosApp/iosApp/Resources/Assets.xcassets/Contents.json new file mode 100644 index 0000000..73c0059 --- /dev/null +++ b/iosApp/iosApp/Resources/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/iosApp/iosApp/Stores/FavoritesStore.swift b/iosApp/iosApp/Stores/FavoritesStore.swift new file mode 100644 index 0000000..4862415 --- /dev/null +++ b/iosApp/iosApp/Stores/FavoritesStore.swift @@ -0,0 +1,31 @@ +import Foundation +import Combine +import shared + +@MainActor +final class FavoritesStore: ObservableObject { + @Published private(set) var favorites: [Pokemon] = [] + + private let viewModel: FavoritesViewModel + private var collectTask: Task? + + init() { + self.viewModel = FavoritesViewModel(repository: KoinHelper.shared.repository) + startCollecting() + } + + private func startCollecting() { + collectTask = Task { [weak self] in + guard let self = self else { return } + for await newFavorites in self.viewModel.favorites.stream() as AsyncStream<[Pokemon]> { + guard !Task.isCancelled else { break } + self.favorites = newFavorites + } + } + } + + deinit { + collectTask?.cancel() + viewModel.onCleared() + } +} diff --git a/iosApp/iosApp/Stores/KoinHelper.swift b/iosApp/iosApp/Stores/KoinHelper.swift new file mode 100644 index 0000000..6ba09ab --- /dev/null +++ b/iosApp/iosApp/Stores/KoinHelper.swift @@ -0,0 +1,26 @@ +import Foundation +import shared + +/// Swift-side helper to access KMP Koin dependencies. +/// +/// Usage: +/// ```swift +/// let repository = KoinHelper.shared.repository +/// let viewModel = PokemonListViewModel(repository: repository) +/// ``` +final class KoinHelper { + static let shared = KoinHelper() + + private var _repository: PokemonRepository? + + private init() {} + + /// The shared PokemonRepository instance from Koin. + /// Lazily resolved on first access. + var repository: PokemonRepository { + if _repository == nil { + _repository = KoinIOSKt.getRepository() + } + return _repository! + } +} diff --git a/iosApp/iosApp/Stores/PokemonDetailStore.swift b/iosApp/iosApp/Stores/PokemonDetailStore.swift new file mode 100644 index 0000000..ce84888 --- /dev/null +++ b/iosApp/iosApp/Stores/PokemonDetailStore.swift @@ -0,0 +1,57 @@ +import Foundation +import Combine +import shared + +@MainActor +final class PokemonDetailStore: ObservableObject { + @Published private(set) var state: PokemonDetailState = PokemonDetailState.Loading.shared + + private let viewModel: PokemonDetailViewModel + private var collectTask: Task? + + init(pokemonName: String) { + self.viewModel = PokemonDetailViewModel( + pokemonName: pokemonName, + repository: KoinHelper.shared.repository + ) + startCollecting() + } + + private func startCollecting() { + collectTask = Task { [weak self] in + guard let self = self else { return } + for await newState in self.viewModel.state.stream() as AsyncStream { + guard !Task.isCancelled else { break } + self.state = newState + } + } + } + + func toggleFavorite() { + viewModel.toggleFavorite() + } + + func retry() { + viewModel.retry() + } + + deinit { + collectTask?.cancel() + viewModel.onCleared() + } +} + +// MARK: - State Helper Extensions +extension PokemonDetailState { + var isLoading: Bool { + self is PokemonDetailState.Loading + } + + var successState: PokemonDetailState.Success? { + self as? PokemonDetailState.Success + } + + var errorState: PokemonDetailState.Error? { + self as? PokemonDetailState.Error + } +} diff --git a/iosApp/iosApp/Stores/PokemonListStore.swift b/iosApp/iosApp/Stores/PokemonListStore.swift new file mode 100644 index 0000000..6bb2ce5 --- /dev/null +++ b/iosApp/iosApp/Stores/PokemonListStore.swift @@ -0,0 +1,58 @@ +import Foundation +import Combine +import shared + +@MainActor +final class PokemonListStore: ObservableObject { + @Published private(set) var state: PokemonListState = PokemonListState.Loading.shared + + private let viewModel: PokemonListViewModel + private var collectTask: Task? + + init() { + self.viewModel = PokemonListViewModel(repository: KoinHelper.shared.repository) + startCollecting() + } + + private func startCollecting() { + collectTask = Task { [weak self] in + guard let self = self else { return } + for await newState in self.viewModel.state.stream() as AsyncStream { + guard !Task.isCancelled else { break } + self.state = newState + } + } + } + + func loadNextPage() { + viewModel.loadNextPage() + } + + func search(_ query: String) { + viewModel.search(query: query) + } + + func refresh() { + viewModel.refresh() + } + + deinit { + collectTask?.cancel() + viewModel.onCleared() + } +} + +// MARK: - State Helper Extensions +extension PokemonListState { + var isLoading: Bool { + self is PokemonListState.Loading + } + + var successState: PokemonListState.Success? { + self as? PokemonListState.Success + } + + var errorState: PokemonListState.Error? { + self as? PokemonListState.Error + } +} diff --git a/iosApp/iosApp/Utilities/PokemonColors.swift b/iosApp/iosApp/Utilities/PokemonColors.swift new file mode 100644 index 0000000..ded075d --- /dev/null +++ b/iosApp/iosApp/Utilities/PokemonColors.swift @@ -0,0 +1,68 @@ +import SwiftUI + +enum PokemonColors { + static let primary = Color("AppPrimaryColor", bundle: nil) + static let secondary = Color("AccentColor", bundle: nil) + + static func typeColor(for type: String) -> Color { + switch type.lowercased() { + case "normal": return Color(hex: "A8A77A") + case "fire": return Color(hex: "EE8130") + case "water": return Color(hex: "6390F0") + case "electric": return Color(hex: "F7D02C") + case "grass": return Color(hex: "7AC74C") + case "ice": return Color(hex: "96D9D6") + case "fighting": return Color(hex: "C22E28") + case "poison": return Color(hex: "A33EA1") + case "ground": return Color(hex: "E2BF65") + case "flying": return Color(hex: "A98FF3") + case "psychic": return Color(hex: "F95587") + case "bug": return Color(hex: "A6B91A") + case "rock": return Color(hex: "B6A136") + case "ghost": return Color(hex: "735797") + case "dragon": return Color(hex: "6F35FC") + case "dark": return Color(hex: "705746") + case "steel": return Color(hex: "B7B7CE") + case "fairy": return Color(hex: "D685AD") + default: return Color.gray + } + } + + static func statColor(for stat: String) -> Color { + switch stat.lowercased() { + case "hp": return Color(hex: "FF5959") + case "attack": return Color(hex: "F5AC78") + case "defense": return Color(hex: "FAE078") + case "special-attack", "sp. atk": return Color(hex: "9DB7F5") + case "special-defense", "sp. def": return Color(hex: "A7DB8D") + case "speed": return Color(hex: "FA92B2") + default: return Color.gray + } + } +} + +extension Color { + init(hex: String) { + let hex = hex.trimmingCharacters(in: CharacterSet.alphanumerics.inverted) + var int: UInt64 = 0 + Scanner(string: hex).scanHexInt64(&int) + let a, r, g, b: UInt64 + switch hex.count { + case 3: + (a, r, g, b) = (255, (int >> 8) * 17, (int >> 4 & 0xF) * 17, (int & 0xF) * 17) + case 6: + (a, r, g, b) = (255, int >> 16, int >> 8 & 0xFF, int & 0xFF) + case 8: + (a, r, g, b) = (int >> 24, int >> 16 & 0xFF, int >> 8 & 0xFF, int & 0xFF) + default: + (a, r, g, b) = (255, 0, 0, 0) + } + self.init( + .sRGB, + red: Double(r) / 255, + green: Double(g) / 255, + blue: Double(b) / 255, + opacity: Double(a) / 255 + ) + } +} diff --git a/iosApp/iosApp/Utilities/StateFlowExtensions.swift b/iosApp/iosApp/Utilities/StateFlowExtensions.swift new file mode 100644 index 0000000..af2d0d3 --- /dev/null +++ b/iosApp/iosApp/Utilities/StateFlowExtensions.swift @@ -0,0 +1,37 @@ +import Foundation +import shared + +extension Kotlinx_coroutines_coreStateFlow { + func stream() -> AsyncStream { + AsyncStream { continuation in + let collector = StateFlowCollector { value in + if let typedValue = value as? T { + continuation.yield(typedValue) + } + } + + Task { + do { + try await self.collect(collector: collector) + } catch { + continuation.finish() + } + } + + continuation.onTermination = { _ in } + } + } +} + +private class StateFlowCollector: Kotlinx_coroutines_coreFlowCollector { + private let onEmit: (Any?) -> Void + + init(onEmit: @escaping (Any?) -> Void) { + self.onEmit = onEmit + } + + func emit(value: Any?, completionHandler: @escaping (Error?) -> Void) { + onEmit(value) + completionHandler(nil) + } +} diff --git a/iosApp/iosApp/Views/Components/FlowLayout.swift b/iosApp/iosApp/Views/Components/FlowLayout.swift new file mode 100644 index 0000000..6d5d01e --- /dev/null +++ b/iosApp/iosApp/Views/Components/FlowLayout.swift @@ -0,0 +1,62 @@ +import SwiftUI + +struct FlowLayout: Layout { + var spacing: CGFloat = 8 + + func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize { + let result = arrangeSubviews(proposal: proposal, subviews: subviews) + return result.size + } + + func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) { + let result = arrangeSubviews(proposal: proposal, subviews: subviews) + + for (index, position) in result.positions.enumerated() { + subviews[index].place( + at: CGPoint(x: bounds.minX + position.x, y: bounds.minY + position.y), + proposal: .unspecified + ) + } + } + + private func arrangeSubviews(proposal: ProposedViewSize, subviews: Subviews) -> (size: CGSize, positions: [CGPoint]) { + let maxWidth = proposal.width ?? .infinity + var positions: [CGPoint] = [] + var currentX: CGFloat = 0 + var currentY: CGFloat = 0 + var lineHeight: CGFloat = 0 + var totalHeight: CGFloat = 0 + var totalWidth: CGFloat = 0 + + for subview in subviews { + let size = subview.sizeThatFits(.unspecified) + + if currentX + size.width > maxWidth && currentX > 0 { + currentX = 0 + currentY += lineHeight + spacing + lineHeight = 0 + } + + positions.append(CGPoint(x: currentX, y: currentY)) + + lineHeight = max(lineHeight, size.height) + currentX += size.width + spacing + totalWidth = max(totalWidth, currentX - spacing) + totalHeight = currentY + lineHeight + } + + return (CGSize(width: totalWidth, height: totalHeight), positions) + } +} + +#Preview { + FlowLayout(spacing: 8) { + ForEach(["Overgrow", "Chlorophyll", "Hidden Power", "Solar Beam"], id: \.self) { ability in + Text(ability) + .padding(.horizontal, 12) + .padding(.vertical, 6) + .background(Capsule().fill(Color.blue.opacity(0.2))) + } + } + .padding() +} diff --git a/iosApp/iosApp/Views/Components/StatBar.swift b/iosApp/iosApp/Views/Components/StatBar.swift new file mode 100644 index 0000000..79a5bfd --- /dev/null +++ b/iosApp/iosApp/Views/Components/StatBar.swift @@ -0,0 +1,62 @@ +import SwiftUI +import shared + +struct StatBar: View { + let stat: PokemonStat + + private var normalizedValue: Double { + min(Double(stat.value) / 255.0, 1.0) + } + + private var displayName: String { + switch stat.name.lowercased() { + case "hp": return "HP" + case "attack": return "Attack" + case "defense": return "Defense" + case "special-attack": return "Sp. Atk" + case "special-defense": return "Sp. Def" + case "speed": return "Speed" + default: return stat.name.capitalized + } + } + + var body: some View { + HStack(spacing: 12) { + Text(displayName) + .font(.subheadline) + .frame(width: 70, alignment: .leading) + .foregroundStyle(.secondary) + + Text("\(stat.value)") + .font(.subheadline) + .fontWeight(.semibold) + .frame(width: 40, alignment: .trailing) + + GeometryReader { geometry in + ZStack(alignment: .leading) { + RoundedRectangle(cornerRadius: 4) + .fill(Color(.systemGray5)) + .frame(height: 8) + + RoundedRectangle(cornerRadius: 4) + .fill(PokemonColors.statColor(for: stat.name)) + .frame(width: geometry.size.width * normalizedValue, height: 8) + .animation(.easeOut(duration: 0.6), value: normalizedValue) + } + } + .frame(height: 8) + } + } +} + +#Preview { + VStack(spacing: 16) { + StatBar(stat: PokemonStat(name: "hp", value: 45)) + StatBar(stat: PokemonStat(name: "attack", value: 49)) + StatBar(stat: PokemonStat(name: "defense", value: 49)) + StatBar(stat: PokemonStat(name: "special-attack", value: 65)) + StatBar(stat: PokemonStat(name: "special-defense", value: 65)) + StatBar(stat: PokemonStat(name: "speed", value: 45)) + } + .padding() +} diff --git a/iosApp/iosApp/Views/Components/TypeChip.swift b/iosApp/iosApp/Views/Components/TypeChip.swift new file mode 100644 index 0000000..c2b9439 --- /dev/null +++ b/iosApp/iosApp/Views/Components/TypeChip.swift @@ -0,0 +1,29 @@ +import SwiftUI + +struct TypeChip: View { + let type: String + + var body: some View { + Text(type.capitalized) + .font(.subheadline) + .fontWeight(.semibold) + .foregroundStyle(.white) + .padding(.horizontal, 16) + .padding(.vertical, 8) + .background( + Capsule() + .fill(PokemonColors.typeColor(for: type)) + ) + .shadow(color: PokemonColors.typeColor(for: type).opacity(0.4), radius: 4, x: 0, y: 2) + } +} + +#Preview { + HStack { + TypeChip(type: "grass") + TypeChip(type: "poison") + TypeChip(type: "fire") + TypeChip(type: "water") + } + .padding() +} diff --git a/iosApp/iosApp/Views/Favorites/FavoritesView.swift b/iosApp/iosApp/Views/Favorites/FavoritesView.swift new file mode 100644 index 0000000..a692a3c --- /dev/null +++ b/iosApp/iosApp/Views/Favorites/FavoritesView.swift @@ -0,0 +1,123 @@ +import SwiftUI +import shared + +struct FavoritesView: View { + @StateObject private var store = FavoritesStore() + + private let columns = [ + GridItem(.flexible(), spacing: 16), + GridItem(.flexible(), spacing: 16) + ] + + var body: some View { + NavigationStack { + ZStack { + Color(.systemGroupedBackground) + .ignoresSafeArea() + + if store.favorites.isEmpty { + emptyStateView + } else { + favoritesGrid + } + } + .navigationTitle("Favorites") + .animation(.easeInOut(duration: 0.3), value: store.favorites.count) + } + } + + private var emptyStateView: some View { + VStack(spacing: 16) { + Image(systemName: "heart.slash") + .font(.system(size: 60)) + .foregroundStyle(.secondary) + + Text("No Favorites Yet") + .font(.title2) + .fontWeight(.semibold) + + Text("Tap the heart icon on any Pokémon\nto add it to your favorites") + .font(.subheadline) + .foregroundStyle(.secondary) + .multilineTextAlignment(.center) + } + .padding() + } + + private var favoritesGrid: some View { + ScrollView { + LazyVGrid(columns: columns, spacing: 16) { + ForEach(store.favorites, id: \.id) { pokemon in + NavigationLink(value: pokemon) { + FavoriteGridCell(pokemon: pokemon) + .transition(.asymmetric( + insertion: .scale.combined(with: .opacity), + removal: .scale.combined(with: .opacity) + )) + } + .buttonStyle(.plain) + } + } + .padding() + } + .navigationDestination(for: Pokemon.self) { pokemon in + PokemonDetailView(pokemonName: pokemon.name) + } + } +} + +struct FavoriteGridCell: View { + let pokemon: Pokemon + + var body: some View { + VStack(spacing: 8) { + ZStack(alignment: .topTrailing) { + AsyncImage(url: URL(string: pokemon.imageUrl)) { phase in + switch phase { + case .empty: + ProgressView() + .frame(width: 100, height: 100) + case .success(let image): + image + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 100, height: 100) + case .failure: + Image(systemName: "photo") + .font(.system(size: 40)) + .foregroundStyle(.secondary) + .frame(width: 100, height: 100) + @unknown default: + EmptyView() + } + } + + Image(systemName: "heart.fill") + .font(.caption) + .foregroundStyle(.red) + .padding(4) + } + + VStack(spacing: 2) { + Text("#\(pokemon.id)") + .font(.caption2) + .foregroundStyle(.secondary) + + Text(pokemon.name.capitalized) + .font(.subheadline) + .fontWeight(.semibold) + .lineLimit(1) + } + } + .padding(12) + .background( + RoundedRectangle(cornerRadius: 16) + .fill(Color(.systemBackground)) + .shadow(color: .black.opacity(0.1), radius: 8, x: 0, y: 4) + ) + } +} + +#Preview { + FavoritesView() +} diff --git a/iosApp/iosApp/Views/PokemonDetail/PokemonDetailView.swift b/iosApp/iosApp/Views/PokemonDetail/PokemonDetailView.swift new file mode 100644 index 0000000..c059343 --- /dev/null +++ b/iosApp/iosApp/Views/PokemonDetail/PokemonDetailView.swift @@ -0,0 +1,249 @@ +import SwiftUI +import shared + +struct PokemonDetailView: View { + let pokemonName: String + @StateObject private var store: PokemonDetailStore + @Environment(\.dismiss) private var dismiss + + init(pokemonName: String) { + self.pokemonName = pokemonName + _store = StateObject(wrappedValue: PokemonDetailStore(pokemonName: pokemonName)) + } + + var body: some View { + ZStack { + backgroundGradient + contentView + } + .navigationBarTitleDisplayMode(.inline) + .toolbar { + ToolbarItem(placement: .topBarTrailing) { + if let success = store.state.successState { + favoriteButton(isFavorite: success.pokemon.isFavorite) + } + } + } + } + + @ViewBuilder + private var backgroundGradient: some View { + if let success = store.state.successState, + let firstType = success.pokemon.types.first { + LinearGradient( + colors: [ + PokemonColors.typeColor(for: firstType).opacity(0.3), + Color(.systemBackground) + ], + startPoint: .top, + endPoint: .center + ) + .ignoresSafeArea() + } else { + Color(.systemBackground) + .ignoresSafeArea() + } + } + + @ViewBuilder + private var contentView: some View { + if store.state.isLoading { + loadingView + } else if let success = store.state.successState { + detailContent(success.pokemon) + } else if let error = store.state.errorState { + errorView(error.message) + } + } + + private var loadingView: some View { + VStack(spacing: 16) { + ProgressView() + .scaleEffect(1.5) + Text("Loading details...") + .font(.subheadline) + .foregroundStyle(.secondary) + } + } + + private func detailContent(_ pokemon: PokemonDetail) -> some View { + ScrollView { + VStack(spacing: 24) { + headerSection(pokemon) + physicalAttributesSection(pokemon) + typesSection(pokemon) + statsSection(pokemon) + abilitiesSection(pokemon) + } + .padding() + } + } + + private func headerSection(_ pokemon: PokemonDetail) -> some View { + VStack(spacing: 8) { + AsyncImage(url: URL(string: pokemon.imageUrl)) { phase in + switch phase { + case .empty: + ProgressView() + .frame(width: 200, height: 200) + case .success(let image): + image + .resizable() + .aspectRatio(contentMode: .fit) + .frame(width: 200, height: 200) + .shadow(color: .black.opacity(0.2), radius: 20, x: 0, y: 10) + case .failure: + Image(systemName: "photo") + .font(.system(size: 80)) + .foregroundStyle(.secondary) + .frame(width: 200, height: 200) + @unknown default: + EmptyView() + } + } + + Text("#\(pokemon.id)") + .font(.subheadline) + .foregroundStyle(.secondary) + + Text(pokemon.name.capitalized) + .font(.largeTitle) + .fontWeight(.bold) + } + } + + private func physicalAttributesSection(_ pokemon: PokemonDetail) -> some View { + HStack(spacing: 40) { + VStack(spacing: 4) { + Image(systemName: "ruler") + .font(.title2) + .foregroundStyle(.secondary) + Text(String(format: "%.1f m", Double(pokemon.height) / 10.0)) + .font(.title3) + .fontWeight(.semibold) + Text("Height") + .font(.caption) + .foregroundStyle(.secondary) + } + + Divider() + .frame(height: 60) + + VStack(spacing: 4) { + Image(systemName: "scalemass") + .font(.title2) + .foregroundStyle(.secondary) + Text(String(format: "%.1f kg", Double(pokemon.weight) / 10.0)) + .font(.title3) + .fontWeight(.semibold) + Text("Weight") + .font(.caption) + .foregroundStyle(.secondary) + } + } + .padding() + .background( + RoundedRectangle(cornerRadius: 16) + .fill(Color(.secondarySystemBackground)) + ) + } + + private func typesSection(_ pokemon: PokemonDetail) -> some View { + VStack(alignment: .leading, spacing: 12) { + Text("Types") + .font(.headline) + + HStack(spacing: 12) { + ForEach(pokemon.types, id: \.self) { type in + TypeChip(type: type) + } + } + } + .frame(maxWidth: .infinity, alignment: .leading) + } + + private func statsSection(_ pokemon: PokemonDetail) -> some View { + VStack(alignment: .leading, spacing: 16) { + Text("Base Stats") + .font(.headline) + + ForEach(pokemon.stats, id: \.name) { stat in + StatBar(stat: stat) + } + } + .padding() + .background( + RoundedRectangle(cornerRadius: 16) + .fill(Color(.secondarySystemBackground)) + ) + } + + private func abilitiesSection(_ pokemon: PokemonDetail) -> some View { + VStack(alignment: .leading, spacing: 12) { + Text("Abilities") + .font(.headline) + + FlowLayout(spacing: 8) { + ForEach(pokemon.abilities, id: \.self) { ability in + Text(ability.capitalized.replacingOccurrences(of: "-", with: " ")) + .font(.subheadline) + .padding(.horizontal, 12) + .padding(.vertical, 6) + .background( + Capsule() + .fill(Color(.tertiarySystemBackground)) + ) + } + } + } + .frame(maxWidth: .infinity, alignment: .leading) + } + + private func favoriteButton(isFavorite: Bool) -> some View { + Button(action: { + withAnimation(.spring(response: 0.3, dampingFraction: 0.6)) { + store.toggleFavorite() + } + }) { + Image(systemName: isFavorite ? "heart.fill" : "heart") + .font(.title2) + .foregroundStyle(isFavorite ? .red : .secondary) + .scaleEffect(isFavorite ? 1.1 : 1.0) + } + } + + private func errorView(_ message: String) -> some View { + VStack(spacing: 16) { + Image(systemName: "exclamationmark.triangle") + .font(.system(size: 50)) + .foregroundStyle(.red) + + Text("Failed to load details") + .font(.headline) + + Text(message) + .font(.subheadline) + .foregroundStyle(.secondary) + .multilineTextAlignment(.center) + + Button(action: { + store.retry() + }) { + Label("Retry", systemImage: "arrow.clockwise") + .font(.headline) + .foregroundStyle(.white) + .padding(.horizontal, 24) + .padding(.vertical, 12) + .background(Color.accentColor) + .clipShape(Capsule()) + } + } + .padding() + } +} + +#Preview { + NavigationStack { + PokemonDetailView(pokemonName: "bulbasaur") + } +} diff --git a/iosApp/iosApp/Views/PokemonList/PokemonGridCell.swift b/iosApp/iosApp/Views/PokemonList/PokemonGridCell.swift new file mode 100644 index 0000000..31361c5 --- /dev/null +++ b/iosApp/iosApp/Views/PokemonList/PokemonGridCell.swift @@ -0,0 +1,61 @@ +import SwiftUI +import shared +struct PokemonGridCell: View { + let pokemon: Pokemon + + var body: some View { + GeometryReader { geometry in + ZStack(alignment: .bottom) { + // Full-bleed image + AsyncImage(url: URL(string: pokemon.imageUrl)) { phase in + switch phase { + case .empty: + Rectangle() + .fill(Color(.systemGray5)) + .overlay(ProgressView()) + case .success(let image): + image + .resizable() + .aspectRatio(contentMode: .fill) + case .failure: + Rectangle() + .fill(Color(.systemGray5)) + .overlay( + Image(systemName: "photo") + .font(.largeTitle) + .foregroundStyle(.secondary) + ) + @unknown default: + EmptyView() + } + } + .frame(width: geometry.size.width, height: geometry.size.width) + .clipped() + + // Gradient overlay with text + LinearGradient( + colors: [.clear, .black.opacity(0.7)], + startPoint: .top, + endPoint: .bottom + ) + .frame(height: 60) + + // Pokemon info overlay + VStack(alignment: .leading, spacing: 2) { + Text(pokemon.name.capitalized) + .font(.subheadline) + .fontWeight(.semibold) + .foregroundStyle(.white) + Text("#\(pokemon.id)") + .font(.caption2) + .foregroundStyle(.white.opacity(0.8)) + } + .frame(maxWidth: .infinity, alignment: .leading) + .padding(10) + } + } + .aspectRatio(1, contentMode: .fit) // Square card + .clipShape(RoundedRectangle(cornerRadius: 12)) + .shadow(color: .black.opacity(0.15), radius: 8, x: 0, y: 4) + } +} diff --git a/iosApp/iosApp/Views/PokemonList/PokemonListView.swift b/iosApp/iosApp/Views/PokemonList/PokemonListView.swift new file mode 100644 index 0000000..3fd2ca6 --- /dev/null +++ b/iosApp/iosApp/Views/PokemonList/PokemonListView.swift @@ -0,0 +1,123 @@ +import SwiftUI +import shared + +struct PokemonListView: View { + @StateObject private var store = PokemonListStore() + @State private var searchText = "" + + private let columns = [ + GridItem(.flexible(), spacing: 16), + GridItem(.flexible(), spacing: 16) + ] + + var body: some View { + NavigationStack { + ZStack { + Color(.systemGroupedBackground) + .ignoresSafeArea() + + contentView + } + .navigationTitle("Pokédex") + .searchable(text: $searchText, prompt: "Search Pokémon") + .onChange(of: searchText) { newValue in + store.search(newValue) + } + } + } + + @ViewBuilder + private var contentView: some View { + if store.state.isLoading { + loadingView + } else if let success = store.state.successState { + successView(success) + } else if let error = store.state.errorState { + errorView(error.message) + } + } + + private var loadingView: some View { + VStack(spacing: 16) { + ProgressView() + .scaleEffect(1.5) + Text("Loading Pokémon...") + .font(.subheadline) + .foregroundStyle(.secondary) + } + } + + private func successView(_ success: PokemonListState.Success) -> some View { + ScrollView { + LazyVGrid(columns: columns, spacing: 16) { + ForEach(success.pokemon, id: \.id) { pokemon in + NavigationLink(value: pokemon) { + PokemonGridCell(pokemon: pokemon) + } + .buttonStyle(.plain) + } + + if success.canLoadMore { + loadMoreView(isLoading: success.isLoadingMore) + } + } + .padding() + .animation(.easeInOut(duration: 0.3), value: success.pokemon.count) + } + .refreshable { + store.refresh() + } + .navigationDestination(for: Pokemon.self) { pokemon in + PokemonDetailView(pokemonName: pokemon.name) + } + } + + private func loadMoreView(isLoading: Bool) -> some View { + Group { + if isLoading { + ProgressView() + .frame(maxWidth: .infinity) + .padding() + } else { + Color.clear + .frame(height: 50) + .onAppear { + store.loadNextPage() + } + } + } + } + + private func errorView(_ message: String) -> some View { + VStack(spacing: 16) { + Image(systemName: "exclamationmark.triangle") + .font(.system(size: 50)) + .foregroundStyle(.red) + + Text("Oops! Something went wrong") + .font(.headline) + + Text(message) + .font(.subheadline) + .foregroundStyle(.secondary) + .multilineTextAlignment(.center) + .padding(.horizontal) + + Button(action: { + store.refresh() + }) { + Label("Try Again", systemImage: "arrow.clockwise") + .font(.headline) + .foregroundStyle(.white) + .padding(.horizontal, 24) + .padding(.vertical, 12) + .background(Color.accentColor) + .clipShape(Capsule()) + } + } + } +} + +#Preview { + PokemonListView() +} diff --git a/iosApp/iosAppTests/FavoritesStoreTests.swift b/iosApp/iosAppTests/FavoritesStoreTests.swift new file mode 100644 index 0000000..c97cae2 --- /dev/null +++ b/iosApp/iosAppTests/FavoritesStoreTests.swift @@ -0,0 +1,25 @@ +import XCTest +@testable import iosApp +import shared + +@MainActor +final class FavoritesStoreTests: XCTestCase { + + func testInitialFavoritesEmpty() async { + let store = FavoritesStore() + + try? await Task.sleep(nanoseconds: 500_000_000) + + XCTAssertNotNil(store.favorites) + } + + func testFavoritesReactiveUpdates() async { + let store = FavoritesStore() + + let initialCount = store.favorites.count + + try? await Task.sleep(nanoseconds: 1_000_000_000) + + XCTAssertEqual(store.favorites.count, initialCount) + } +} diff --git a/iosApp/iosAppTests/PokemonColorsTests.swift b/iosApp/iosAppTests/PokemonColorsTests.swift new file mode 100644 index 0000000..528966a --- /dev/null +++ b/iosApp/iosAppTests/PokemonColorsTests.swift @@ -0,0 +1,61 @@ +import XCTest +import SwiftUI +@testable import iosApp + +final class PokemonColorsTests: XCTestCase { + + func testTypeColorReturnsCorrectColorForKnownTypes() { + let fireColor = PokemonColors.typeColor(for: "fire") + let waterColor = PokemonColors.typeColor(for: "water") + let grassColor = PokemonColors.typeColor(for: "grass") + + XCTAssertNotEqual(fireColor, waterColor) + XCTAssertNotEqual(waterColor, grassColor) + XCTAssertNotEqual(fireColor, grassColor) + } + + func testTypeColorCaseInsensitive() { + let lowerCase = PokemonColors.typeColor(for: "fire") + let upperCase = PokemonColors.typeColor(for: "FIRE") + let mixedCase = PokemonColors.typeColor(for: "Fire") + + XCTAssertEqual(lowerCase, upperCase) + XCTAssertEqual(lowerCase, mixedCase) + } + + func testTypeColorReturnsGrayForUnknownType() { + let unknownColor = PokemonColors.typeColor(for: "unknown_type") + let expectedGray = Color.gray + + XCTAssertEqual(unknownColor, expectedGray) + } + + func testStatColorReturnsCorrectColorForKnownStats() { + let hpColor = PokemonColors.statColor(for: "hp") + let attackColor = PokemonColors.statColor(for: "attack") + let defenseColor = PokemonColors.statColor(for: "defense") + + XCTAssertNotEqual(hpColor, attackColor) + XCTAssertNotEqual(attackColor, defenseColor) + } + + func testColorHexInitializer() { + let redColor = Color(hex: "FF0000") + let greenColor = Color(hex: "00FF00") + let blueColor = Color(hex: "0000FF") + + XCTAssertNotEqual(redColor, greenColor) + XCTAssertNotEqual(greenColor, blueColor) + XCTAssertNotEqual(redColor, blueColor) + } + + func testColorHexInitializerWithShortFormat() { + let shortHex = Color(hex: "F00") + XCTAssertNotNil(shortHex) + } + + func testColorHexInitializerWithAlpha() { + let colorWithAlpha = Color(hex: "80FF0000") + XCTAssertNotNil(colorWithAlpha) + } +} diff --git a/iosApp/iosAppTests/PokemonListStoreTests.swift b/iosApp/iosAppTests/PokemonListStoreTests.swift new file mode 100644 index 0000000..4eff04c --- /dev/null +++ b/iosApp/iosAppTests/PokemonListStoreTests.swift @@ -0,0 +1,31 @@ +import XCTest +@testable import iosApp +import shared + +@MainActor +final class PokemonListStoreTests: XCTestCase { + + func testInitialState() async { + let store = PokemonListStore() + + let initialState = store.state + XCTAssertTrue(initialState is PokemonListStateLoading) + } + + func testSearchUpdatesState() async { + let store = PokemonListStore() + + try? await Task.sleep(nanoseconds: 2_000_000_000) + + store.search("pikachu") + + try? await Task.sleep(nanoseconds: 500_000_000) + + if case let success as PokemonListStateSuccess = store.state { + let filteredPokemon = success.pokemon + for pokemon in filteredPokemon { + XCTAssertTrue(pokemon.name.lowercased().contains("pikachu")) + } + } + } +} diff --git a/shared/shared.podspec b/shared/shared.podspec index a0d10e0..aeef86e 100644 --- a/shared/shared.podspec +++ b/shared/shared.podspec @@ -1,36 +1,20 @@ Pod::Spec.new do |spec| spec.name = 'shared' spec.version = '1.0.0' - spec.homepage = '' + spec.homepage = 'https://github.com/Robustrade/Pokedex-assignment' spec.source = { :path => '.' } - spec.authors = '' + spec.authors = 'Pokemon Assignment' + spec.license = { :type => 'MIT' } spec.summary = 'PokemonKMP Shared Module' spec.ios.deployment_target = '16.0' - spec.vendored_frameworks = 'build/cocoapods/framework/shared.framework' + spec.vendored_frameworks = 'build/XCFrameworks/debug/shared.xcframework' + + spec.libraries = 'c++', 'sqlite3' + spec.static_framework = true spec.pod_target_xcconfig = { 'KOTLIN_PROJECT_PATH' => ':shared', 'PRODUCT_MODULE_NAME' => 'shared', } - - spec.script_phases = [ - { - :name => 'Build shared', - :execution_position => :before_compile, - :shell_path => '/bin/sh', - :script => <<-SCRIPT - if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then - echo "Skipping Kotlin build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" - exit 0 - fi - set -ev - REPO_ROOT="$SRCROOT/.." - "$REPO_ROOT/gradlew" -p "$REPO_ROOT" :shared:syncFramework \ - -Pkotlin.native.cocoapods.platform=$PLATFORM_NAME \ - -Pkotlin.native.cocoapods.archs="$ARCHS" \ - -Pkotlin.native.cocoapods.configuration="$CONFIGURATION" - SCRIPT - } - ] end diff --git a/shared/src/iosMain/kotlin/com/assignment/pokemon/di/KoinIOS.kt b/shared/src/iosMain/kotlin/com/assignment/pokemon/di/KoinIOS.kt new file mode 100644 index 0000000..ff0b09e --- /dev/null +++ b/shared/src/iosMain/kotlin/com/assignment/pokemon/di/KoinIOS.kt @@ -0,0 +1,18 @@ +package com.assignment.pokemon.di + +import com.assignment.pokemon.data.repository.PokemonRepository +import org.koin.core.component.KoinComponent +import org.koin.core.component.get + +/** + * iOS-specific Koin helper to expose dependencies to Swift. + * This is necessary because Koin's internals are not directly accessible from Swift. + */ +object KoinIOS : KoinComponent { + fun getRepository(): PokemonRepository = get() +} + +/** + * Helper function for Swift to get the repository. + */ +fun getRepository(): PokemonRepository = KoinIOS.getRepository()